将 Theme.Dialog 更改为 Android 中的 Theme.Light.Dialog

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10915492/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:27:25  来源:igfitidea点击:

Change Theme.Dialog to look like Theme.Light.Dialog in Android

androiddialogstylesthemes

提问by Rynardt

There is no Theme.Light.Dialogto use with the rest of my project that is using Theme.Light.

有没有Theme.Light.Dialog我的项目的其余部分正在使用使用Theme.Light

How can I change Theme.Dialogto look like a Theme.Lightversion of Dialog.

我怎样才能改变Theme.Dialog看起来像一个Theme.Light版本Dialog

I know that I must overwrite sections of Theme.Dialogin styles.xml as below. What items should I overwrite with which values?

我知道我必须如下覆盖Theme.Dialogstyle.xml 中的部分。我应该用哪些值覆盖哪些项目?

<style name="dialog_light" parent="@android:style/Theme.Dialog">
    <item name="android:???????"></item>
    <item name="android:???????"></item>
</style>

I could just make the background that light white grey, but the buttons, spinners etc are also different on the light theme to look better on the light background.

我可以将背景设为浅白灰色,但浅色主题上的按钮、微调器等也不同,以便在浅色背景上看起来更好。

EDIT

编辑

Looks like I got it working.

看起来我得到了它的工作。

<color name="black">#FF000000</color>
<color name="whitegrey">#FFF2F2F2</color>

<style name="dialog_light" parent="@android:style/Theme.Dialog">
    <item name="@android:windowBackground">@color/whitegrey</item>
    <item name="@android:textColor">@color/black</item>        
</style>

回答by Rynardt

Looks like I got it working.

看起来我得到了它的工作。

<color name="black">#FF000000</color>
<color name="whitegrey">#FFF2F2F2</color>

<style name="dialog_light" parent="@android:style/Theme.Dialog">
    <item name="@android:windowBackground">@color/whitegrey</item>
    <item name="@android:textColor">@color/black</item>        
</style>

回答by Georgie

Further to the above, to avoid making up colors, I did this:

除上述之外,为了避免化妆颜色,我这样做了:

<!-- Makes a "light" equivalent of Theme.Dialog -->
<style name="dialog_light" parent="@android:style/Theme.Dialog">
    <item name="@android:background">@android:color/background_light</item>
    <item name="@android:textColor">@android:color/primary_text_light</item>    
</style>

回答by Couitchy

This is good, thanks! I just changed it a bit: when I run what you suggested, the entire screen is painted with the back color and the dialog does not look as it should (with the previous activity dimmed).

这个不错,谢谢!我只是改变了一点:当我运行你的建议时,整个屏幕都涂上了背景色,对话框看起来不像它应该的样子(之前的活动变暗了)。

So instead of using

所以而不是使用

@android:windowBackground

just use

只是使用

@android:background