问题
I want the change the look of the preferences screen for an app I am working on. On some phones the preferences are very translucent and it is quite difficult to read the preferences scheme, so I am going to change the visuals for it.
My question is how can I apply a theme to the preferences scheme? Or failing that, how can I change the text color that show up for the various preferences.
In my current version, my preferences layout xml file starts with:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffa0a0a0">
This background color gives me an acceptable gray, but I would prefer to use a theme.
I tried putting a applying a couple of different themes in the preferences xml and the preferences layout xml and none of this has shown any effect. I also tried setting andoid:textColor for the individual preferences items and in layout and that had no effect.
So how does one modify the visuals for the preferences scheme (preferably by using a theme)?
thanks in advance,
Jay
回答1:
The basic things are:
- A theme for your preferences activity which defines styles for the preference widgets and other things. Take a look at the first theme in themes.xml - this defines the window background, text styles and the preference styles (
preferenceScreenStyle
,preferenceCategoryStyle
etc) - Some styles for each of the preference widgets (which are referenced in
themes.xml
). For instance in styles.xml they define thePreference.Category
andPreference.PreferenceScreen
styles. - Apply the theme to your Activity. In your manifest change your opening activity tag for your preferences activity to
<activity android:theme="@style/CustomTheme"...
If you want to inherit the default Android styles and then just override some of them, then add parent="@android:style/Theme"
to the opening <style...
tag of your theme.
Take a look at Applying Styles and Themes for more info.
来源:https://stackoverflow.com/questions/5561874/using-a-theme-for-preferences-screen