如何在 Android 中更改首选项类别的文本颜色? [英] How to change text color of preference category in Android?

查看:20
本文介绍了如何在 Android 中更改首选项类别的文本颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

textColor 属性不起作用.这是我的 XML:

The textColor attribute isn't working. Here's my XML:

<PreferenceCategory
        android:title="Title"
        android:textColor="#00FF00">

有什么想法吗?

推荐答案

使用这个自定义的 PreferenceCategory 类:

use this customize PreferenceCategory class :

public class MyPreferenceCategory extends PreferenceCategory {
    public MyPreferenceCategory(Context context) {
        super(context);
    }

    public MyPreferenceCategory(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyPreferenceCategory(Context context, AttributeSet attrs,
            int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    protected void onBindView(View view) {
        super.onBindView(view);
        TextView titleView = (TextView) view.findViewById(android.R.id.title);
        titleView.setTextColor(Color.RED);
    }
}

并将其添加到您的 Pref.xml 文件中:

and add this at your Pref.xml file :

<ali.UI.Customize.MyPreferenceCategory android:title="@string/pref_server" />

这篇关于如何在 Android 中更改首选项类别的文本颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆