0

I have a functional settings screen by following the doc But I am unable to control the colors/style (e.g. of CheckBoxPreference). The settings shows up like this
enter image description here
I have tried several combinations in themes.xml but unable to find mistake. Went through the related stackoverflow questions but unable to make them work + information is too old.

By overriding onCreateView in code (as suggested here) and specifying a style partially works. But I will prefer to resolve this via themes.xml .

My themes.xml code snippet is as follows:

 <style name="Theme.MyApp" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
...
 <item name="colorSecondary">@color/RED</item> 
...
<!-- Below lines I have tried 1 at a time as well -->
 <item name="preferenceTheme">@style/SettingsTheme</item>
 <item name="android:settingsActivity">@style/SettingsTheme</item>
 <item name="android:preferenceScreenStyle">@style/SettingsTheme</item>
...
...
 <style name="SettingsTheme"  parent="@style/PreferenceThemeOverlay.v14.Material">
   <item name="colorControlNormal">@color/TEAL</item>
   <item name="colorControlActivated">@color/PURPLE</item>
 </style>`

Other details

In gradle

implementation 'androidx.preference:preference:1.2.0'
implementation 'androidx.appcompat:appcompat:1.4.1'

main activity layout xml snippet

<androidx.fragment.app.FragmentContainerView
    android:id="@+id/settings_container"
    android:layout_width="wrap_content"
 ...

root_preferences.xml snippet

<PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">

<EditTextPreference
    app:key="@string/prefKeyUname"
    app:title="@string/prefTitleUname"
    app:useSimpleSummaryProvider="true"

    app:isPreferenceVisible="true"
    app:enabled="true"
    app:defaultValue="anonymous"
    />

<CheckBoxPreference
    app:key="music"
    app:title="Music"
    app:summaryOn="Background music enabled"
    app:summaryOff="Background music disabled"
    app:defaultValue="true"
    />
...

In my activity java code , I have

public static class SettingsFragment extends PreferenceFragmentCompat {

    @Override
    public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
        setPreferencesFromResource(R.xml.root_preferences, rootKey);
...

Thanks for reading through and help.

Amit
  • 173
  • 7

0 Answers0