【问题标题】:Android CheckBoxPreference title colorAndroid CheckBoxPreference 标题颜色
【发布时间】:2012-08-17 10:47:50
【问题描述】:

我正在使用answer 中的代码。

但我没有为我使用的文本视图设置 android:textColor

style="?background_text_color_theme"

必须根据应用程序的主题设置文本颜色(黑色主题为白色文本颜色,反之亦然)。这适用于除 CheckBoxPreference 之外的所有其他地方。

我对我提供的链接所做的更改:

      <TextView android:id="@+android:id/title"
        android:layout_width="wrap_content" android:layout_height="wrap_content"
        android:singleLine="true" 
        android:ellipsize="marquee" android:fadingEdge="horizontal"
        style="?background_text_color_theme" />

这是我的 style.xml:

    <style name="background_text_color_theme_bl">
    <item name="android:textColor">#ffffff</item>

</style>    

     <style name="background_text_color_theme_wh">
    <item name="android:textColor">#000000</item>

</style>    

Themes.Xml:

    <style name="Theme.White"  parent="@android:style/Theme.Holo.Light">
    <item name="background_text_color_theme">@style/background_text_color_theme_wh</item>
</style> 

   <style name="Theme.Black"  parent="@android:style/Theme.Holo">
    <item name="background_text_color_theme">@style/background_text_color_theme_bl</item>
</style>

但是文字颜色好像不是按照样式设置的。谁能告诉我为什么会这样?

谢谢。

【问题讨论】:

    标签: android checkbox textcolor preferencescreen


    【解决方案1】:

    我是这样做的。以防万一将来有人需要它。

        public class CheckBoxPreferenceClass extends CheckBoxPreference {
    
    
        public CheckBoxPreferenceClass(Context context) {
            super(context);
        }
    
        public CheckBoxPreferenceClass(Context context, AttributeSet attrs) {
            super(context, attrs);
        }
        public CheckBoxPreferenceClass(Context context, AttributeSet attrs, int defStyle) {
            super(context, attrs, defStyle);
        }
    
        @Override
        protected void onBindView(View view) {
            super.onBindView(view);
            TextView title = (TextView) view.findViewById(android.R.id.title);
            title.setTextColor(Color.BLACK);
        }
    
    }
    

    并且在首选项 xml 中使用它作为复选框首选项:

      <packagename.CheckBoxPreferenceClass
            android:key="@string/imp"
            android:title="@string/title"/>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 1970-01-01
      • 2013-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多