android-preferences

Create PreferenceDialog onClick on filter popup?

大城市里の小女人 提交于 2019-12-24 23:13:01
问题 My goal is to implement the image below. How to create a PreferenceDialog if the filter icon in my toolbar has been clicked? I want to set some preferences to filter the entries of my list. I'm at this point. Is that the right way to implement this? 回答1: Yes sir, it is! You should inflate the resource first and set it as a custom view. AlertDialog should do the trick after that. Do you have any further question? Or do you only need to check if it's the right way to do it? 来源: https:/

Managing SharedPreferences in both PreferenceActivity and Service within same app

六眼飞鱼酱① 提交于 2019-12-24 12:03:11
问题 I'm building an app with a PreferenceActivity and a Service (running in its own remote process due to android:process=":remote" flag) and both need to access programmatically the SharedPreferences . At present time I'm getting a SharedPreference object with the following code that uses the getSharedPreferences method defined in both Service and PreferenceActivity classes: SharedPreferences sharedPrefs = getSharedPreferences("com.mypackage_preferences", MODE_PRIVATE, MODE_MULTI_PROCESS) Is

accessing a class from another activity

≡放荡痞女 提交于 2019-12-24 09:40:02
问题 Have following setup: MainActivity class - extends activity MyLayout class - extends View Prefs class - extends PreferenceActivity and implements OnSharedPreferenceChangeListener MainActivity creates a MyLayout class and sets it as its contentview. Once the user presses on the menu, Prefs class starts where the user can change some settings. What I want is that, once the user changes a setting, the overloaded OnsharedPreferenceChanged method in the Prefs class will be called and from there I

SharedPreferences or SQLite Database?

烈酒焚心 提交于 2019-12-24 03:18:52
问题 I'm writing a small alarm clock application, and I'm currently using SharedPreferences to store the settings for each alarm. I figured this would be more lightweight than using the SQLite Database, but now I'm thinking about writing a small thread-safe wrapper for SharedPreference. Am I being an idiot and should just use the database or would this still be more light-weight than the database? 回答1: For something this small, how lightweight it is isn't really relevant. Its a matter of 10

RingtonePreference Theme

萝らか妹 提交于 2019-12-24 02:14:39
问题 Im creating an Android App, totaly in Holo.Light Theme. All the preferences are light, except for the Ringtonepreference! I have even tried setting the BGColor and the textColor in the Preferences.xml: <RingtonePreference android:icon="@drawable/ic_menu_note" android:key="ringtone" android:persistent="true" android:summary="@string/settings_ringtone2" android:background="#000000" android:textColor="#ffffff" android:title="@string/settings_ringtone" /> Android ignores everything.. Has anybody

The method addPreferencesFromResource(int) from the type PreferenceActivity is deprecated

允我心安 提交于 2019-12-24 01:44:28
问题 What are the other methods to replace the method addPreferencesFromResource(R.xml.prefs); Can this will get any errors in feauture 回答1: Use PreferenceFragment instead. You may face some troubles in the future, right now PreferenceActivity works fine. 来源: https://stackoverflow.com/questions/18998590/the-method-addpreferencesfromresourceint-from-the-type-preferenceactivity-is-d

Can't get onSharedPreferenceChanged() to work

拈花ヽ惹草 提交于 2019-12-23 19:24:51
问题 I wanna display a dialog when the user selects a specific item from a ListPreference in my preferenceActivity. But, I cannot get the onSharedPreferenceChanged() to work. I've put a Toast in the beginning of the method, and it does not show, so the method doesn't even run through, why is this? Here's my code: (Thanks) public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Toast.makeText(Preferences.this, "prefs Changed", Toast.LENGTH_SHORT) .show(); if (key

Android store array in preferences

隐身守侯 提交于 2019-12-23 17:19:29
问题 I know only primitives can be stored in the android preferences, but do arrays count? Can I store an array of, say, Strings or booleans in an android preference? 回答1: Only if you turn the array into a string. 回答2: SharedPreferences settings = getSharedPreferences(PREFS_NAME,0); for(int n =0;n<LevelMenu.buttonState.length;n++){ LevelMenu.buttonState[n]= (byte) settings.getInt("levelsave"+n,0); } Above will get and populate the array and below will depopulate and save. SharedPreferences

Android JUnit testing of Preferences

只谈情不闲聊 提交于 2019-12-23 15:14:51
问题 A fairly normal scenario: an Android application has a preferences activity, and selecting an option from a ListPreference triggers code to change that ListPreference's summary text. ie: Selecting "Green" from a color ListPreference would change the ListPreference's summary text to "Green" through a onPreferenceChange callback. I'd like to be able to use the Android JUnit testing to confirm that these summary changes are all being performed correctly. However, there seems to be very little

Preference setIcon to ColorDrawable does not work on Android 5.0 Lollipop

扶醉桌前 提交于 2019-12-23 13:14:21
问题 In my app I use the following line to distinguish some preferences: preference.setIcon(new ColorDrawable(color)); In Android versions prior to Lollipop it works fine and the preference shows a square icon of the selected color, but in Lollipop none is shown. Any idea for how to solve it? Thanks Here is a solution that is working for me: preference.setIcon(getPreferenceIcon(color)); function Drawable getPreferenceIcon(int color) { if (Build.VERSION.SDK_INT < 21) return new ColorDrawable(color)