android – 如何使用自定义主题设置DialogPreference样式?

android – 如何使用自定义主题设置DialogPreference样式?,第1张

概述在我的应用程序中,我使用Theme.Holo和Theme.Holo.Light没有任何问题.当使用Holo主题并单击DialogPreference / ListPreference时,d出的对话框也以Holo为主题.对于Holo.Light来说也是如此.但是,当我的自定义主题(来自Holo.Light)设置了PreferencesActivity样式时,所有对话框都以Holo.Light为主题. 在我的应用程序中,我使用theme.Holo和theme.Holo.light没有任何问题.当使用Holo主题并单击DialogPreference / ListPreference时,d出的对话框也以Holo为主题.对于Holo.light来说也是如此.但是,当我的自定义主题(来自Holo.light)设置了PreferencesActivity样式时,所有对话框都以Holo.light为主题.我想我在主题中缺少某些东西.谁能帮助我?非常感谢!

这是我的主题代码:

<?xml version="1.0" enCoding="utf-8"?><!-- Generated with http://androID-holo-colors.com --><resources xmlns:androID="http://schemas.androID.com/apk/res/androID">  <style name="Greentheme" parent="androID:theme.Holo.light">    <item name="androID:editTextBackground">@drawable/edit_text_holo_light</item>    <item name="androID:autoCompleteTextVIEwStyle">@style/autoCompleteTextVIEwGreentheme</item>    <item name="androID:ListChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>    <item name="androID:ListChoiceIndicatorSingle">@drawable/btn_radio_holo_light</item>    <item name="androID:buttonStyle">@style/buttonGreentheme</item>    <item name="androID:imagebuttonStyle">@style/ImagebuttonGreentheme</item>    <item name="androID:dropDownSpinnerStyle">@style/SpinnerGreentheme</item>    <item name="androID:tabWidgetStyle">@style/TabWidgetGreentheme</item>    <item name="androID:progressbarStyleHorizontal">@style/ProgressbarGreentheme</item>    <item name="androID:seekbarStyle">@style/SeekbarGreentheme</item>    <item name="androID:buttonStyletoggle">@style/ToggleGreentheme</item>    <item name="androID:ListChoiceBackgroundindicator">@drawable/List_selector_holo_light</item>    <item name="androID:activatedBackgroundindicator">@drawable/activated_background_holo_light</item>    <item name="androID:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>    <item name="androID:actionbarStyle">@style/Actionbar.solID.Greenactionbar</item>    <item name="androID:buttonbarbuttonStyle">@style/buttonbarbuttonStyleGreentheme</item>    <item name="androID:preferenceStyle">@style/TimePickerDialogFragmentGreen</item>  </style>      <style name="TimePickerDialogFragmentGreen" parent="@androID:style/theme.Holo.light.Dialog">         <item name="androID:editTextBackground">@drawable/edit_text_holo_light</item>    <item name="androID:autoCompleteTextVIEwStyle">@style/autoCompleteTextVIEwGreentheme</item>    <item name="androID:ListChoiceIndicatorMultiple">@drawable/btn_check_holo_light</item>    <item name="androID:ListChoiceIndicatorSingle">@drawable/btn_radio_holo_light</item>    <item name="androID:buttonStyle">@style/buttonGreentheme</item>    <item name="androID:imagebuttonStyle">@style/ImagebuttonGreentheme</item>    <item name="androID:dropDownSpinnerStyle">@style/SpinnerGreentheme</item>    <item name="androID:tabWidgetStyle">@style/TabWidgetGreentheme</item>    <item name="androID:progressbarStyleHorizontal">@style/ProgressbarGreentheme</item>    <item name="androID:seekbarStyle">@style/SeekbarGreentheme</item>    <item name="androID:buttonStyletoggle">@style/ToggleGreentheme</item>    <item name="androID:ListChoiceBackgroundindicator">@drawable/List_selector_holo_light</item>    <item name="androID:activatedBackgroundindicator">@drawable/activated_background_holo_light</item>    <item name="androID:fastScrollThumbDrawable">@drawable/fastscroll_thumb_holo</item>    <item name="androID:actionbarStyle">@style/Actionbar.solID.Greenactionbar</item>    <item name="androID:buttonbarbuttonStyle">@style/buttonbarbuttonStyleGreentheme</item>    </style></resources>
解决方法 我找到了 this rather unformatted but otherwise nice answer.

要点是DialogPreferences是在没有the theme parameter的情况下创建的AlertDialogs,这意味着它们应用了androID:alertDialogtheme所指向的主题.

所以我扩展了这样的主题,以对话为主题:

<resources>    <!-- Base application theme. -->    <style name="Apptheme" parent="theme.AppCompat.light">        <item name="colorPrimary">@color/yellow_500</item>        <item name="colorPrimaryDark">@color/yellow_a700</item>        <item name="colorAccent">@color/purple_400</item>        <item name="androID:alertDialogtheme">@style/Dialogtheme</item>    </style>    <style name="Dialogtheme" parent="theme.AppCompat.light.Dialog">        <item name="colorPrimary">@color/yellow_500</item>        <item name="colorPrimaryDark">@color/yellow_a700</item>        <item name="colorAccent">@color/purple_400</item>        <item name="androID:windowMinWIDthMinor">@androID:dimen/dialog_min_wIDth_minor</item>    </style></resources>

Apptheme中的colorPrimary,colorPrimaryDark和colorAccent也是我想要应用于对话框的颜色.

请注意,我需要androID:windowMinWIDthMinor来防止对话框水平折叠.

总结

以上是内存溢出为你收集整理的android – 如何使用自定义主题设置DialogPreference样式?全部内容,希望文章能够帮你解决android – 如何使用自定义主题设置DialogPreference样式?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1141019.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存