【问题标题】:Is there a way to style PreferenceFragmentCompat有没有办法设置 PreferenceFragmentCompat 的样式
【发布时间】:2016-02-12 01:17:53
【问题描述】:

标题说明了一切:如何设置 PreferenceFragmentCompat 的样式。我的 v14/style.xml 是

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:editTextStyle">@style/Widget.EditText.White</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay</item>
    </style>

    <style name="Widget.EditText.White" parent="@android:style/Widget.EditText">
        <item name="android:textColor">#ffffffff</item>
    </style>
</resources>

基本主题具有黑色背景 - 首选项屏幕因此无法读取,因为我在黑色背景上有黑色文本。

我尝试了很多方法,但无法更改文本颜色。

我必须做的是在设置片段处于活动状态时将片段容器背景颜色设置为白色。一个丑陋的黑客,而不是我想做的事。

【问题讨论】:

标签: android android-styles preferencefragment


【解决方案1】:

回答我自己的问题:我的 v14/style.xml 现在是

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <item name="android:editTextStyle">@style/Widget.EditText.White</item>
        <item name="preferenceTheme">@style/PreferenceThemeOverlay.v14.Material</item>
    </style>

    <style name="Widget.EditText.White" parent="@android:style/Widget.EditText">
        <item name="android:textColor">#ffffffff</item>
    </style>

    <style name="PreferenceThemeOverlay.v14">
        <item name="android:background">@color/settings_background</item>
        <item name="android:textColor">@color/settings_text_colour</item>
        <item name="android:textColorSecondary">@color/settings_text_colour_secondary</item>
    </style>
</resources>

我现在的问题是设置 ListPreference 的样式。

为什么这么难?如果有任何与样式偏好相关的文档,它会被很好地隐藏。呸呸呸!

【讨论】:

  • 现在是 2019 年,即使使用偏好材料设计 v14 支持库,偏好样式仍然不自然。终于用 deprecated 解决方法与您的答案类似...我支持您的 Grrrrrr! >:(
  • 现在是 2020 年,我可以找到完全为零的方法来设置首选项的文本颜色(默认为黑色,我在任何地方都没有使用)。又是一整天的地狱。再次感谢,安卓。我第三你的Grrrrrr! >:-(
【解决方案2】:

查看 github 项目的 README Gericop/Android-Support-Preference-V7-Fix

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-17
    • 2021-05-18
    • 1970-01-01
    • 2022-06-29
    • 2015-03-07
    • 2012-05-28
    • 2011-02-28
    相关资源
    最近更新 更多