在Android List Preference中设置自定义主题

5
在我的Android应用中,我在不同的活动中使用各种自定义主题,所有这些主题都正常工作。所有这些主题都使用相同的自定义样式来设置按钮、编辑控件等。
我的首选项使用标准的首选项活动,在XML中定义并通过清单文件进行样式设置。
然而,当我有一个首选项导致警报对话框被启动时,例如ListPreference,该对话框使用标准按钮。它似乎在EditTextPreference中使用了我的自定义EditText样式...但没有使用我的背景或文本颜色。
有人知道为什么会发生这种情况吗?
一些代码:
样式:
<style name="Theme.Prefs" parent="@android:style/Theme.Holo.Light">
        <item name="android:windowBackground">@drawable/background</item>
    <item name="android:buttonStyle">@style/CustomButtonStyle</item>
        <item name="android:editTextStyle">@style/CustomEditTextStyle</item>
</style>


<style name="CustomButtonStyle" parent="@android:style/Widget.Holo.Button">
    <item name="android:background">@drawable/custom_button</item>
    <item name="android:textSize">@dimen/dialog_text_size_normal</item>
    <item name="android:textColor">@color/dialog_control_colour</item>
</style>


<style name="CustomEditTextStyle" parent="@android:style/Widget.Holo.EditText">
    <item name="android:background">@drawable/custom_textfield</item>
    <item name="android:textColor">@color/dialog_control_colour</item>
    <item name="android:textSize">@dimen/dialog_text_size_normal</item>
</style>

而在清单文件中:

<activity
    android:name="com.breadbun.prefs.MainPreferencesActivity"
    android:theme="@style/Theme.Prefs"
    android:screenOrientation="portrait">
</activity>
1个回答

1

要自定义alertDialog,您需要将第二行添加到主题中,然后按照您想要的方式自定义DialogStyle。

<style name="AppTheme" parent="android:Theme.Material">
    <item name="android:alertDialogTheme">@style/DialogStyle</item>
</style>
<style name="DialogStyle" parent="android:Theme.Material.Dialog.Alert">
</style>

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接