【问题标题】:Android PreferenceFragment appcompat style ignored <21Android PreferenceFragment appcompat 样式被忽略 <21
【发布时间】:2015-12-21 08:54:47
【问题描述】:

我正在使用 PreferenceActivity 将 PreferenceFragments 添加到我的布局中。 PreferenceActivity 正在使用带有父 Theme.AppCompat.Light.NoActionBar 的自定义样式,我已为其更新了 colorPrimary、colorPrimaryDark 和 colorAccent。在棒棒糖上,首选项屏幕按预期显示,使用适当的颜色和文本样式,但是,在 KitKat 上,我使用的样式似乎完全被忽略了。

最初我认为问题在于 PreferenceActivity 扩展了 Activity 而不是 AppCompatActivity,但我什至尝试在我的偏好活动中使用 AppCompatDelegate,但这并没有帮助。为什么

【问题讨论】:

  • 是警报对话框忽略了主题吗?
  • 不,每个 PreferenceCategory 及其下的 ListPreference 项。
  • 我认为主题Theme.AppCompat.Light.NoActionBar 是用于更高版本的api,旧版本可能不支持。
  • @Ibukun 不。 v7 AppCompat 库支持低至 7 的所有 API。
  • 哦,我明白了,谢谢@AdityaNaik

标签: android


【解决方案1】:

我认为您可以通过为对话框制作自定义样式来解决此问题,然后使用 dialogThemealertDialogTheme 属性在您的基本应用主题中引用它。

<!-- Your base app theme -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        ...
       <item name="dialogTheme">@style/MyDialogStyle</item>
       <item name="alertDialogTheme">@style/MyDialogStyle</item>
</style>

<!-- Custom style for dialogs -->    
<style name="MyDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
            <item name="colorAccent">@color/accent_pink_a200</item>
            <item name="android:textColorPrimary">@color/white</item>
            <item name="android:textColorSecondary">@color/white</item>
            <item name="android:background">@color/primary_deepPurple_500</item>
            <item name="textColorAlertDialogListItem">@color/white</item>
            <item name="android:textAppearanceButton">@style/TextAppearance.Widget.AppCompat.Toolbar.Title</item>
</style>

您还可以根据需要在自定义样式中包含colorPrimarycolorPrimaryDark 等其他属性。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-01
    • 2014-12-13
    • 2016-07-24
    • 2018-08-04
    • 2013-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多