Closed tomsr closed 7 years ago
You should be able to load the value from shared preferences as an integer (which is how android represents colours), e.g...
https://stackoverflow.com/a/17916954
Use the same key that you specified in your preference screen xml.
Hi, sorry do not understand, here how it looks from my side. Preference screen, all good, can go in and pick color. After exit it is saved somewhere, I guess shared preferences. Because when i come back in app second time, newly picked color is there.
PreferenceScreen start xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto"
<com.rarepebble.colorpicker.ColorPreference
android:key="listColor"
android:title="@string/listColor"
android:defaultValue="#abcfb4"
/>
PreferenceScreen end
Get color: SharedPreferences sharedPreferences = getActivity().getSharedPreferences("listColor", 0); int listColor = sharedPreferences.getInt("listColor", 0);
and I never get color. Where is the problem?
You should probably use getDefaultSharedpreferences(). "listColor" is probably not the name of your preferences file.
Thanks Martin, Your color library is perfect. Worked as You said: SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext()); int listColor = prefs.getInt("listColor", 0); Thankyou very much.
Hi, I am doing something wrong - how can I get already selected color code from preference screen, in my fragment class? Could not find in examples.