Id like to add an my app version and possibly build on the my SettingsActivity.
Im trying to show an "About Phone" style activity on my app. But I dont know how to go about it.
I am currently using EditTextPreference in my preference.xml which calls a dialog on Click, but I want it to be like this, where the onClick event doesnt produce a dialog.:
SettingsActivity.java
public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.pref_general);
}
@Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
LinearLayout root = (LinearLayout)findViewById(android.R.id.list).getParent().getParent().getParent();
Toolbar bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.tool_bar, root, false);
root.addView(bar, 0); // insert at top
bar.setTitle("Settings");
bar.setNavigationOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
finish();
}
});
}
}
pref_general.xml
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
android:title="Settings">
<PreferenceCategory android:title="About" >
<EditTextPreference
android:title="Version"
android:summary="@string/app_version"
android:key="prefUsername"/>
</PreferenceCategory>
And one more thing, is there a way to get the app and build number from gradle via xml.
I know I code like a caveman and I usually manually update them in the strings.xml, but in my defense I am new to Android.