changing the preference category label color background

故事扮演 提交于 2019-12-05 21:21:40

I think the problem is that you are trying to pass a style/theme that only has a background color specified in it when it is expecting a style/theme/layout that contains a view to replace the current view in the preference with.

The example in the documentation for android:widgetLayout says

a checkbox preference would specify a custom layout (consisting of just the CheckBox) here

Another option would be to try and do this in code by overriding the onBindView() of the PreferenceCategory.

and yes, changing the theme in the AndroidManfiest.xml should change the background color (in this case) for the entire Application or Activity depending on where you specified it.

Hpsaturn

To me, this works:

For example ListSeparator item:

In styles.xml

<style name="ListSeparator">
<item name="android:background">@drawable/status_bar</item>
<item name="android:layout_width">match_parent</item>
<item name="android:layout_height">25dip</item>
<item name="android:textStyle">bold</item>
<item name="android:textColor">@color/black</item>
<item name="android:textSize">14sp</item>
<item name="android:gravity">center_vertical</item>
<item name="android:paddingLeft">5sp</item>
</style>

<color name="custom_theme_color">#e6e6e6</color>

<style name="CustomTheme" parent="android:Theme.Light.NoTitleBar">
<item name="android:windowBackground">@color/custom_theme_color</item>
<item name="android:colorBackground">@color/custom_theme_color</item>
<item name="android:listSeparatorTextViewStyle">@style/ListSeparator</item>
</style>

Then, in AndroidManifest.xml:

<activity
android:name="MyActivityPreference"
android:theme="@style/CustomTheme" >
</activity>

Or view this thread: https://stackoverflow.com/a/5564943/471690

This is solution for my problem. In my file for example preference_category.xml I have to have a simple layout for the PreferenceCategory and than use it in android:layout. However android:widgetLayout doesn't work.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/my_blue"
>
<TextView 
android:id="@+android:id/title"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:textColor="@color/my_white"
android:textStyle="bold"
android:textSize="16sp"
android:padding="5dp"
android:layout_marginLeft="10dp"
/>     
</LinearLayout>

Another solution that worked for me is just to copy the preference_category.xml into res/layout folder and change the values right from there.

<?xml version="1.0" encoding="utf-8"?>
    <!-- Layout used for PreferenceCategory in a PreferenceActivity. -->
    <TextView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="?android:attr/listSeparatorTextViewStyle"
        android:textColor="@color/colorPrimaryDark"
        android:id="@android:id/title"
        />

Just give the what ever color you want at the android:textColor="@color/colorPrimaryDark" block

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!