【问题标题】:How can I set dialog style in my custom theme?如何在自定义主题中设置对话框样式?
【发布时间】:2013-04-18 10:48:25
【问题描述】:

我尝试了很多方法,但我无法从 xml 更改 AlertDialog 样式。

我想要的结果是为扩展和覆盖默认值的对话框定义 XML 样式,然后将其绑定到我的主题中,这样所有的 alertDialogs 看起来都一样。

我试过了:

<style name="AppTheme" parent="AppBaseTheme">
    <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="android:alertDialogStyle">@style/pippo</item>
</style>
<style name="pippo" parent="@android:style/Theme.Dialog">
    <item name="android:bottomBright">@android:color/holo_orange_dark</item>
    <item name="android:bottomDark">@android:color/holo_orange_dark</item>
    <item name="android:bottomMedium">@android:color/holo_orange_dark</item>
    <item name="android:centerBright">@android:color/holo_orange_dark</item>
    <item name="android:centerDark">@android:color/holo_orange_dark</item>
    <item name="android:centerMedium">@android:color/holo_orange_dark</item>
    <item name="android:fullBright">@android:color/holo_orange_dark</item>
    <item name="android:fullDark">@android:color/holo_orange_dark</item>
    <item name="android:topBright">@android:color/holo_blue_dark</item>
    <item name="android:topDark">@android:color/holo_blue_dark</item>
</style>

然后我将清单“AppTheme”作为活动主题放入,但我仍然看到正常的警报对话框。

我哪里做错了?

【问题讨论】:

  • 将代码发布到您在 AlertDialog 中添加此样式的位置。
  • 我没有通过java添加样式,我想通过覆盖默认样式来设置对话框样式。

标签: android


【解决方案1】:

您可以尝试这样的方法来应用所需的样式:

AlertDialog.Builder builder = new AlertDialog.Builder(new ContextThemeWrapper(this, R.style. pippo));

【讨论】:

  • 是的,但这不是我想要的。我想只使用 xml 来实现这个结果。
  • 我不认为这是可能的。但是,您可以创建一个扩展 AlertDialog 的自定义对话框类,并在构造函数上应用该样式。然后,调用您的 CustomDialog 而不是 AlertDialog。
猜你喜欢
  • 1970-01-01
  • 2013-07-04
  • 2014-05-20
  • 1970-01-01
  • 1970-01-01
  • 2013-04-20
  • 2012-07-05
  • 1970-01-01
  • 2023-03-20
相关资源
最近更新 更多