2
此刻,我扩展Dialog
并使用构造函数Dialog(Context context, int theme)
通过主题设置背景颜色。该对话框是一个叠加层,因此它位于屏幕上显示的所有内容之上。主题如下:可以更改没有主题的对话框的窗口背景颜色?
<style
name="Theme.example"
parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">false</item>
<item name="android:windowFullscreen">false</item>
<item name="android:windowAnimationStyle">@null</item>
<item name="android:windowFrame">@null</item>
<item name="android:windowBackground">@color/background_color</item>
</style>
请注意,此主题通过android:windowBackground
属性设置背景颜色。我需要整个屏幕更改颜色,包括通知栏。但我也希望能够在显示对话框后以Java动态更改背景。我想出的最好方法是使用getWindow().setBackgroundDrawableResource(R.drawable.background)
,其中Drawable
只是我想要的颜色的单个像素。
有没有更好的方法来做到这一点?我目前的方法工作正常,但能够使用我没有在R.drawable
中预定义的颜色会很好。
干杯!效果很好。 :) – Glitch