android - 更改 Android 中首选项类别的文本颜色和水平颜色

标签 android android-preferences

我想更改我的首选项类别的颜色,并将默认水平线更改为蓝色。这可能吗?

我尝试使用以下内容设置首选项设置的主题:

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

但我得到以下输出:

enter image description here

我的首选项.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>

有人可以帮我解决这个问题,如上面的屏幕截图所示吗?

谢谢!

最佳答案

您可以创建自定义 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

关于android - 更改 Android 中首选项类别的文本颜色和水平颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25771247/

相关文章:

android - 为什么在将 prefs.getString 的结果与零进行比较时,我得到的是错误的?

android - 如何获取Android Preferences DataStore的所有键

java - 偏好设置中的 Android 按钮更改 MainActivity

android - Android系统升级后应用偏好是否保留?

java - 如何使用 DOM 检查返回的服务器代码?

android - Perl IO::Socket::SSL 持久 TCP 连接

java - 如何以编程方式将编辑文本的文本对齐方式设置为底部?

android - 不同移动平台的文件格式是什么

android - 启动 Android 默认网络浏览器后处理返回点击

android - 设置上的多行标签