灯主题为AlertDialog?主题、AlertDialog

2023-09-07 03:44:12 作者:感谢所有

我创建一个AlertDialog。我使用的setView()设置一个自定义视图。这使得黑暗的主题上的对话(灰色背景和需要白色文本)。

I'm creating an AlertDialog. I'm using setView() to set a custom view. This enables the 'dark' theme on the dialog (grey background, and need white text).

有没有办法来设置为使用光为主题的对话?它看起来更好(白色背景,黑色文本)。

Is there a way to set the dialog to use the 'light' theme? It looks nicer (white background, dark text).

感谢

推荐答案

我的步骤了:

创建一个类扩展对话框。 在的onCreate,通话 的setContentView(X,Y)与X为 您R.layout和Y是 R.style.popupStyle(见下文)。 在RES /价值/ style.xml,你 需要覆盖默认 DialogWindow风格。我尝试过 使得有这个作为一个风格 其母公司,但仍然没有 清除所有默认设置。于是我查了 机器人的git树,并得到了默认 风格,只是复制粘贴它。本 是一个 Create a class extending Dialog. In the onCreate, call setContentView(x, y) with x being your R.layout and y being R.style.popupStyle (see below). In your res/values/style.xml, you need to override the default DialogWindow style. I tried just making a style that has this one as its parent, but that still didn't clear all defaults. So I checked the Android git tree and got the default style, and just copy-pasted it. This is the one

<style name="Theme.Dialog">
    <item name="android:windowFrame">@null</item>
    <item name="android:windowTitleStyle">@android:style/DialogWindowTitle</item>
    <item name="android:windowBackground">@android:drawable/panel_background</item>
    <item name="android:windowIsFloating">true</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item>
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
</style>

您会得到一些错误,只是解决这些问题从官方Android styles.xml和的themes.xml文件复制更多的东西。

You'll get a few errors, just solve them by copying more stuff from the official Android styles.xml and themes.xml files.

,以供参考: styles.xml 和的themes.xml 。