Dependent preferences display wrong color font when disabled

删除回忆录丶 提交于 2019-12-23 07:16:15

问题


In my app I am using several preferences, including some of them related with dependencies using the following attribute: android:dependency="pref_key".

Basically, when the checkbox is not selected, all the other preferences below are disabled:

The problem happens when I setup back the following 3 lines in my custom theme:

<style name="AppThemeOrange" parent="@style/AppTheme">
        <item name="android:textColorPrimary">@color/OrangeMain</item>
        <item name="android:textColorSecondary">@color/OrangeDark</item>
        <item name="android:textColorTertiary">@color/OrangeLight</item>
(...)

The colors defined on these 3 attributes also override the default font color of the disabled preferences:

The preferences are still well disabled, but the fonts displayed make believe the contrary...

I searched in the default Holo Light styles and theme, but I have no idea where this is defined and why the styles above override these ones.

Did anyone already meet the problem?


回答1:


you should define a color state list and put it inside the /res/color folder

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:state_enabled="false" android:color="#FF00ff00"/>
    <item android:color="#FFff0000"/>
</selector>


来源:https://stackoverflow.com/questions/17123133/dependent-preferences-display-wrong-color-font-when-disabled

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!