【问题标题】:Set custom theme in Android List Preference在 Android List Preference 中设置自定义主题
【发布时间】:2013-05-12 20:26:23
【问题描述】:

在我的 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>

【问题讨论】:

    标签: android themes preference


    【解决方案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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-07-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多