I am currently trying to customize color of the preference section. But I don't know how to do that.
In my app I have two themes: Dark Theme And Light Theme. It is an option that the user chooses. In my main activity I set the theme chosen by the user.
And after I use attr to define which color to display.
But in my preference fragment I don't know how to proceed. I read that I have to create new style, in other thread, the solution is to create my custom listPreference... What is the best way to do that?
for example, "year formation" and "group" are disabled so I want to show it (change color of disabled fields)
current listPreference:
Here I want a dark background.
CODE: style.xml
<resources>
<!-- theme clair -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Color -->
<item name="colorAppBarAndDrawer">@color/colorAppBarAndDrawerLight</item>
<item name="colorBackground">@color/colorBackgroundLight</item>
<item name="colorText">@color/colorTextLight</item>
<item name="colorTextSecondary">@color/colorTextSecondaryLight</item>
<item name="colorItem">@color/colorItemLight</item>
<!-- images -->
<item name="iconRefresh">@drawable/ic_refresh_black_24dp</item>
<item name="iconFirstPage">@drawable/ic_first_page_black_24dp</item>
<item name="iconSchedule">@drawable/ic_schedule_black_24dp</item>
<!-- menu -->
<item name="android:actionMenuTextColor">@color/colorTextLight</item>
<item name="android:textColorSecondary">@color/colorTextSecondaryLight</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textColor">@color/colorTextLight</item>
</style>
<!-- theme sombre -->
<style name="AppThemeNight" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorAppBarAndDrawer">@color/colorAppBarAndDrawerDark</item>
<item name="colorBackground">@color/colorBackgroundDark</item>
<item name="colorText">@color/colorTextDark</item>
<item name="colorItem">@color/colorItemDark</item>
<item name="colorTextSecondary">@color/colorTextSecondaryDark</item>
<!-- images -->
<item name="iconRefresh">@drawable/ic_refresh_white_24dp</item>
<item name="iconFirstPage">@drawable/ic_first_page_white_24dp</item>
<item name="iconSchedule">@drawable/ic_schedule_white_24dp</item>
<!-- menu -->
<item name="android:actionMenuTextColor">@color/colorTextDark</item>
<item name="android:textColorSecondary">@color/colorTextSecondaryDark</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textColor">@color/colorTextDark</item>
</style>
<style name="PreferenceThemeOverlay.v14" parent="@style/PreferenceFixTheme.DayNight.NoActionBar">
<!--<item name="android:background">?attr/colorAppBarAndDrawer</item>
<item name="android:textColor">?attr/colorText</item>
<item name="android:textColorSecondary">?attr/colorTextSecondary</item>-->
<item name="colorAccent">#1976D2</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
</resources>
Like I said, I have tried solution. What I have to do?
Thanks a lot
EDIT I changed preferenceActivity to preferenceActivityCompat, now I can change color of switch buttons. in style.xml I added this:
<style name="PreferenceThemeOverlay.v14" parent="@style/PreferenceFixTheme.DayNight.NoActionBar">
<!--<item name="android:background">?attr/colorAppBarAndDrawer</item>
<item name="android:textColor">?attr/colorText</item>
<item name="android:textColorSecondary">?attr/colorTextSecondary</item>-->
<item name="colorAccent">#1976D2</item>
</style>
So I did'nt find real solution. I used the theme editor in Android Studio and chose colors with the color picker. Now it works. I dont know if I should make this post as "solved" ? Thanks Thomas