@Override annotation error (android prefs)
You can go to Project settings –> Java Compiler, and switch the compiler compliance level to 1.6. I have to do it every time i import an existing project.
You can go to Project settings –> Java Compiler, and switch the compiler compliance level to 1.6. I have to do it every time i import an existing project.
Do SharedPreferences.OnSharedPreferenceChangeListener spChanged = new SharedPreferences.OnSharedPreferenceChangeListener() { @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // your stuff here } }; In your PreferenceActivity, ie make it a member of your PreferenceActivity class and then do registerOnSharedPreferenceChangeListener(spChanged) in the PreferenceActivity.onCreate() method. That’s what I do and I never have a problem. Else it’s your conditional … Read more
Actually there is a better hack to fix this, also with resource overriding: Create res/values-sw360dp-v13/values-preference.xml: <?xml version=”1.0″ encoding=”utf-8″?> <resources xmlns:tools=”http://schemas.android.com/tools”> <bool name=”config_materialPreferenceIconSpaceReserved” tools:ignore=”MissingDefaultResource,PrivateResource”>false</bool> <dimen name=”preference_category_padding_start” tools:ignore=”MissingDefaultResource,PrivateResource”>0dp</dimen> </resources> The <bool> fixes the default value of iconSpacePreserved for all Preference; The <dimen> fixes the PreferenceCategory. EDIT: If you are using androidx.preference:preference:1.1.0-alpha01 or above, you won’t need the … Read more
Every XML element in Android can be created programmatically as the element name is also a Java class. Hence you can create a ListPreference in code: CharSequence[] entries = { “One”, “Two”, “Three” }; CharSequence[] entryValues = { “1”, “2”, “3” }; ListPreference lp = new ListPreference(this); lp.setEntries(entries); lp.setEntryValues(entryValues); You could alternatively create it in … Read more
I assume by preferences you are referring to your application’s preferences and not Android phone settings. To store preferences between runs of you application you need to do the following Create a SharedPreferences object SharedPreferences settings = getSharedPreferences(String n, MODE_PRIVATE); String n identifies your preferences and the second argument is the mode they’ll be accessed … Read more
AndroidX makes it simple, but I wish it was better documented. In XML To add/remove dividers between preferences in XML, use the following attributes: <androidx.preference.PreferenceScreen xmlns:app=”http://schemas.android.com/apk/res-auto”> <Preference … app:allowDividerAbove=”true/false” app:allowDividerBelow=”true/false” … /> </androidx.preference.PreferenceScreen> Note, a divider will only be shown between two preferences if the top divider has allowDividerBelow set to true and the bottom … Read more
Since Android 6.0 it has been possible to use: <application android:allowBackup=”true”> By setting it to true your data (sharedprefs and others) will be saved on Google cloud and restored next time the app is installed. You can read more about it here. It should be noted that the default settings is true since 6.0.
UPDATE 2018: PercentRelativeLayout and PercentFrameLayout are deprecated. Consider using ConstraintLayout Old Answer: So far Android Support library has limited on where to use this: with RelativeLayout android.support.percent.PercentRelativeLayout with FrameLayout android.support.percent.PercentFrameLayout How to use it? Well, first make sure to include the dependency at build.grade(Module: app) in your android app. dependencies { compile ‘com.android.support:percent:23.3.0’ } Then … Read more
For the xml: <Preference android:title=”Acts like a button” android:key=”@string/myCoolButton” android:summary=”This is a cool button” /> Then for the java in your onCreate() Preference button = findPreference(getString(R.string.myCoolButton)); button.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { //code for what you want it to do return true; } }); This will appear like a normal Preference, with … Read more
I found this post (What to use instead of “addPreferencesFromResource” in a PreferenceActivity?) that help me understand that you have to go through a PreferenceFragment in order to do it. In the following explanation I use your.package. just to show that you have to put the package name. Everybody has its own package so please … Read more