android-preferences

Android changing the background color for preference fragment

这一生的挚爱 提交于 2019-12-05 01:05:22
I have set a theme for my application, which includes a blue background... However, this made my preference fragment blue too. I want to keep the original "android:Theme.Holo.Light.DarkActionBar". How to do so? thanks! Add the following code to your PreferenceFragment implementation: @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); view.setBackgroundColor(getResources().getColor(android.R.color.your_color)); return view; } you can use a style file or in your

PreferenceFragment is shown transparently

守給你的承諾、 提交于 2019-12-05 00:25:29
I'm trying to show a PreferenceFragment after I select the Preferences option in my ActionBar. However, after replacing current content with the PreferenceFragment you can see the old content below it. As in, you can see straight through the preferences. Am I missing something here? I used an example from a book I own, which didn't use any layout files for the preferences. Do you need those? Used code: Actionbar menu private boolean MenuChoice(MenuItem item) { switch (item.getItemId()) { case 0: FragmentManager fragmentManager = getFragmentManager(); FragmentTransaction fragmentTransaction =

getDefaultSharedPreferences in a BroadcastReceiver

早过忘川 提交于 2019-12-04 22:58:21
I was just guessing how to access the DefaultSharedPreferences (set in a PreferenceActivity) from an application in a BroadcastReceiver, knowing that onReceive method comes with Context and Intent? Best regards, In the BroadcastReceiver: PreferenceManager.getDefaultSharedPreferences(context) Looking at the source of it, we can see getDefaultSharedPreferences actually uses getSharedPreferences. So we can use getSharedPreferences the same we getDefaultSharedPreferences uses it. In this specific case (onReceive of a BroadcastReceiver) : SharedPreferences settings = context.getSharedPreferences

Add up button to PreferenceScreen

ε祈祈猫儿з 提交于 2019-12-04 21:40:49
问题 I can't figure out how I would go about implementing an up button in a PreferenceScreen . An up button displays a caret in your action bar next to your app icon that allows you to navigate the app's hierarchy, more info here. I have a Preference Fragment that displays when my main activity is opened and I can get the up button to display by adding this line " getActionBar().setDisplayHomeAsUpEnabled(true);": protected void onCreate(Bundle savedInstanceState) { super.onCreate

Layout for TimePicker-based DialogPreference

ぐ巨炮叔叔 提交于 2019-12-04 21:05:38
I'm writing an app that requires a TimePicker-based preference (two, actually) and I swiped some (Apache-licensed) code from the Android Programming Tutorials book. I've modified it to work a little better, but there's one thing puzzling me. I haven't tried it on an actual device yet but on emulators it now takes into account system settings for 24-hour time display, clears focus on the TimePicker dialog so that the time is read even when edited manually instead of using the arrow keys, and - the problematic part - displays the selected time in the PreferenceScreen. The problem is that I've

How to wrap preference title?

我是研究僧i 提交于 2019-12-04 20:36:52
问题 In this picture, the title of my Preference does not wrap around its parent. How can I make the title wrap to a new line? Thanks. xml: <CheckBoxPreference android:key="keypref" android:summary="Summary text does wrap around the borders" android:title="The title of this preference is" > </CheckBoxPreference> 回答1: You would need to make custom layout which resembles default (android internal) CheckBoxPreference. In that xml text view of title should be with ellipsize set to Marque, repeat limit

What's different between OnPreferenceChangeListener and OnSharedPreferenceChangeListener

久未见 提交于 2019-12-04 17:57:24
问题 I want to get value of a checkboxpreference. which method is suitable for listen to preference? And what's real difference between OnPreferenceChangeListener and OnSharedPreferenceChangeListener ?! UPDATE Why onSharedPreferenceChanged not called? public class Setting extends PreferenceActivity implements OnSharedPreferenceChangeListener // ,OnPreferenceChangeListener { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource

Rotating Android device while viewing dialog preference with TimePicker or NumberPicker causes app crash

不羁岁月 提交于 2019-12-04 17:00:33
I've made a custom DialogPreference which uses two NumberPicker widgets on it to allow a user to select an hour of the day as well as another custom DialogPreference which allows a user to select a time of day using a TimePicker widget. As long as the dialog is not open and I rotate the screen, everything works as desired. However, if the dialog is open and the screen is rotated then the entire app crashes. I've placed break points in the onSaveInstanceState and onRestoreInstanceState methods and have verified that everything that is needed to restore the DialogPreference is in order, the

Applying custom theme to ActionBar in PreferenceFragment

人盡茶涼 提交于 2019-12-04 14:47:50
I am trying to apply custom theme to ActionBar in PreferenceFragment . Following is the scenerio: My class extends PreferenceFragment in which I am adding preferences from resouces as: addPreferenceFromResource (R.xml.myPrefs); Also, I have written: ActionBar a = getActivity ().getActionBar (); bar.setNavigationMode (ActionBar.NAVIGATION_MODE_TABS); Now I want to apply my own theme that I defined in styles.xml to this action bar. Currently, the height of action bar is smaller that the tab view due to which the view is getting cropped. I tried searching but couldn't find a solution to my

Can't get settings button to display for live wallpaper

折月煮酒 提交于 2019-12-04 13:10:00
I want to add settings to a live wallpaper I created. I am missing something very fundamental about how SharedPreferences work. The code and XML are based on the cube live wallpaper example and I can’t figure out what I did wrong. My problem is that no "Settings" button shows up when I choose my live wallpaper from the list. Only the "Set Wallpaper" button is displayed. I suspect that I screwed up something in the XML. This is a very simple live wallpaper I made just to fool around with settings. All it does is set the background to either blue or green (and that part works). What I believe to