2014-09-10 70 views
2

我想更改我的偏好类别的颜色,并将默认水平线更改为蓝色。这可能吗?在android中更改偏好类别的文本颜色和水平颜色

我试图设置主题为偏好设置如下:

<style name="myPreferenceTheme" parent="@style/AppBaseTheme"> 
    <item name="android:textColor">@color/blue</item> 
</style> 

,但我得到了作为输出如下:

enter image description here

我preference.xml看起来是这样的:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > 
<PreferenceCategory 
    android:title="ACCOUNT" > 
    <Preference 
     android:key="googleAccount" 
     android:summary="" 
     android:title="Google Account" > 
    </Preference> 
    <Preference 
     android:key="signoutmenu" 
     android:summary="" 
     android:title="Sign out" > 
    </Preference> 
</PreferenceScreen> 

有人可以帮我解决这个问题像上面的截图中显示的起诉?

谢谢!

+0

它不是一个答案。但这可能会帮助你 http://stackoverflow.com/questions/6297635/custom-preferencecategory-headings – 2014-09-10 17:28:09

回答

2

您可以创建一个自定义的PreferenceCategory并更改“onBindView”方法的标题颜色(在该示例中,类别标题颜色更改为红色)。

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); 
    } 

}

This link has the original solution from where I got this answer