Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text color of PreferenceCategory/PreferenceScreen

Here is the:

preferences.xml

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" >

    <PreferenceCategory
        android:key="@string/pref_basicsettings_key"
        android:title="@string/pref_basicsettings_title" >
        <CheckBoxPreference
            android:defaultValue="@string/pref_test1_default"
            android:key="@string/pref_test1_key"
            android:summary="@string/pref_test1_dlg"
            android:title="@string/pref_test1_title" />
        <CheckBoxPreference
            android:defaultValue="@string/pref_test2_default"
            android:key="@string/pref_test2_key"
            android:summary="@string/pref_test2_dlg"
            android:title="@string/pref_test2_title" />
    </PreferenceCategory>
</PreferenceScreen>

BasicSettingsActivity.java

public class BasicSettingsActivity extends PreferenceActivity {

    public static final String TAG = BasicSettingsActivity.class
            .getSimpleName();

    /** Called when the activity is first created. */
    @SuppressWarnings("deprecation")
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        prefs.registerOnSharedPreferenceChangeListener(mSharedPreferenceListener);

        // add preference resource
        addPreferencesFromResource(com.testapp.R.xml.basic_settings);
    }
}

How do I change the text color in PreferenceCategory?

like image 225
ssk Avatar asked Jun 21 '16 03:06

ssk


People also ask

How to change text color of preference category text?

To change text color of preference category only set a theme to your PreferenceActivity in your Android Manifest and make sure that colorAccent item exists. This color is taken by your PreferenceCategory. Show activity on this post. Actually just found out that preference category text using colorAccent.

How do I change the color of a text selection?

How To Change Text Selection Color Use the ::selectionselector to override the default text selection color: Example ::-moz-selection { /* Code for Firefox */ color: red; background: yellow; ::selection { color: red; background: yellow;

How to override the default text selection color with CSS?

Learn how to override the default text selection color with CSS. Text Selection Color Select the following text: Default text selection color Custom text selection color How To Change Text Selection Color Use the ::selectionselector to override the default text selection color: Example ::-moz-selection { /* Code for Firefox */ color: red;

How to make a custom layout for a preferencescreen?

One solution is to make a theme for your PreferenceScreen. So in your themes.xml or styles.xml (better to put it in themes.xml) : then in your AndroidManifest.xml : It worked perfectly for me. Show activity on this post. An easy way to do this is to set the custom layout for the preferenceCategory here:


2 Answers

I added a new style:

<style name="PreferenceScreen" parent="Theme.AppCompat">
    <item name="android:textColor">#ffffff</item>
    <item name="android:textColorPrimary">#ffffff</item>
    <item name="colorPrimary">#ff0000</item>
    <item name="colorPrimaryDark">#ff0000</item>
    <item name="colorAccent">#ff0000</item>
    <item name="android:background">#CCCCCC</item>
</style>

and included it in the activity:

<activity android:name="com.smartipcamera.owlcam.ui.BasicSettingsActivity"
    android:theme="@style/PreferenceScreen" >
</activity>
like image 68
ssk Avatar answered Nov 16 '22 02:11

ssk


add a new style

<style name="SettingStyle">
    <item name="android:background">#FFFFFF</item>
    <item name="android:textViewStyle">@style/PreferenceStyle</item>
</style>
<style name="PreferenceStyle" parent="android:Widget.TextView">
    <item name="android:textColor">#000000</item>
</style>

and include it in the Preference activity.

public class SettingsActivity extends AppCompatActivity {

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.setting);

    setTheme(R.style.SettingStyle);
    ....

}
like image 42
Andy Cheng Avatar answered Nov 16 '22 03:11

Andy Cheng