Android 偏好类别样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21956823/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:21:52  来源:igfitidea点击:

Android Preference Category Styling

androidstyles

提问by Peter Sun

I am trying to change the color of the text and the background of the preference categories. I searched the webs for answers, but nothing seems to be working. Has anyone successfully changed the color of the preference category attributes? Could I use a custom layout to change looks and feel of the preference category? I need some more direction. Please help

我正在尝试更改首选项类别的文本颜色和背景。我在网上搜索了答案,但似乎没有任何效果。有人成功更改了偏好类别属性的颜色吗?我可以使用自定义布局来更改首选项类别的外观吗?我需要更多的方向。请帮忙

Here is what I have so far:

这是我到目前为止所拥有的:

<style name="Theme" parent="@style/android:Theme.Holo.Light">
    <item name="android:actionBarStyle">@style/ActionBar</item>
</style>

<style name="ActionBar" parent="@android:style/Widget.Holo.Light.ActionBar.Solid">
    <item name="android:background">@color/ab_grey</item>
</style>

<style name="PrefCatStyle" parent="Theme">
    <item name="android:textColor">@color/text_green</item>
    <item name="android:background">@color/pref_back</item>
</style>

colors

颜色

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="ab_grey">#adadad</color> <!--  #adadad--> 
    <color name="text_green">#000000</color>
    <color name="pref_back">#FFFFFF</color>
</resources>

Part of my Preference Layout

我的偏好布局的一部分

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory 
        android:title="Settings"
        android:key="settings_category"
        style="@style/PrefCatStyle">

And my part Manifest

而我的那部分清单

    <application
        android:allowBackup="true"
        android:icon="@drawable/icon"
        android:label="@string/app_name"
        android:theme="@style/Theme" > 
...
        <activity
            android:name=".SettingsPrefActivity"
            android:parentActivityName=".MainActivity"
            android:theme="@style/emTextTheme">

Thanks

谢谢

采纳答案by Kelum Deshapriya

yes. you can use custom layout. take a look at the answer of this question. Custom PreferenceCategory Headings

是的。您可以使用自定义布局。看看这个问题的答案。自定义首选项类别标题