如何改变preference类文本颜色的Andr​​oid?文本、颜色、preference、Andr

2023-09-06 02:20:06 作者:给我马不停蹄的滚

的文字颜色属性不工作。这里是我的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" />