相关疑难解决方法(0)

如何自定义列表首选项单选按钮

我已经在我的应用程序中自定义了所有的radioButtons,但listPreference中的radioButtons没有自定义.

我使用了这个名为btn_radio.xml的xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:state_window_focused="false"
      android:drawable="@drawable/radio_selected" />
<item android:state_checked="false" android:state_window_focused="false"
      android:drawable="@drawable/radio_unselected" />

<item android:state_checked="true" android:state_pressed="true"
      android:drawable="@drawable/radio_selected" />
<item android:state_checked="false" android:state_pressed="true"
      android:drawable="@drawable/radio_unselected" />

<item android:state_checked="true" android:state_focused="true"
      android:drawable="@drawable/radio_selected" />
<item android:state_checked="false" android:state_focused="true"
      android:drawable="@drawable/radio_unselected" />

<item android:state_checked="false" android:drawable="@drawable/radio_unselected" />
<item android:state_checked="true" android:drawable="@drawable/radio_selected" />
</selector>
Run Code Online (Sandbox Code Playgroud)

这是customRadioButton,它扩展了android自定义单选按钮

<style name="CustomRadioButton"    Parent="@android:style/Widget.CompoundButton.RadioButton">
    <item name="android:button">@drawable/btn_radio</item>
</style>
Run Code Online (Sandbox Code Playgroud)

在我的应用程序的主题中,我做了这个改变

<item name="android:radioButtonStyle">@style/CustomRadioButton</item>
    <item name="android:listChoiceIndicatorSingle">@style/CustomRadioButton</item>
Run Code Online (Sandbox Code Playgroud)

此更改会自定义我的应用程序中的所有radioButtons,但ListPreference中的radioButtons除外

customization android radio-button listpreference

12
推荐指数
1
解决办法
1万
查看次数

列表首选项文本颜色

我很难尝试设置 ListPreference 的样式。

我应用了一个主主题,它声明了一个首选项主题,它们都链接到一个对话框主题(分别是 alertDialogTheme)。它的工作原理是项目的文本颜色不会改变 - 但所有其他文本的颜色会改变。我不能依赖解决方法,因为我使用的是 v7 首选项,因此无法覆盖自定义类中的对话框方法。
对我来说,行看起来像是忽略了文本颜色值,但也许其他人对此有解决方案。否则这可能是一个错误?

主要款式:

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- [...] -->        
    <!-- Some color values -->

    <item name="android:dialogTheme">@style/DialogTheme</item>
    <item name="android:alertDialogTheme">@style/DialogTheme</item>
    <item name="dialogTheme">@style/DialogTheme</item>
    <item name="alertDialogTheme">@style/DialogTheme</item>
    <item name="preferenceTheme">@style/PreferenceTheme</item>

</style>
Run Code Online (Sandbox Code Playgroud)


偏好主题:

<style name="PreferenceTheme" parent="PreferenceThemeOverlay.v14.Material">
    <!-- [...] -->
    <!-- Some color values -->
    <item name="android:textColor">@color/preference_primary_color</item>
    <item name="android:textColorPrimary">@color/preference_primary_color</item>
    <item name="android:textColorSecondary">@color/preference_primary_color</item>
    <item name="android:textColorHighlight">@color/preference_primary_color</item>
    <item name="android:editTextColor">@color/preference_primary_color</item>

    <item name="android:dialogTheme">@style/DialogTheme</item>
    <item name="android:alertDialogTheme">@style/DialogTheme</item>
    <item name="preferenceTheme">@style/PreferenceTheme</item>
</style>
Run Code Online (Sandbox Code Playgroud)


对话主题:

<style name="DialogTheme" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="android:textColor">#EEEEEE</item>
    <item name="android:textColorPrimary">#EEEEEE</item>
    <item name="android:textColorSecondary">#EEEEEE</item>
    <item name="android:textColorHighlight">#EEEEEE</item>
    <item name="android:textColorTertiary">#EEEEEE</item>
    <item name="android:textColorAlertDialogListItem">#EEEEEE</item>
    <item name="android:editTextColor">#EEEEEE</item> …
Run Code Online (Sandbox Code Playgroud)

android android-preferences

2
推荐指数
1
解决办法
1569
查看次数