Android 6 中的 windowBackground(棉花糖)
windowBackground in Android 6 (Marshmallow)
我已经使用以下元素为我的应用程序定义了一个基本样式:
<item name="android:windowBackground">@color/window_background</item>
在我在 Android 6 上测试我的应用程序之前,它已经为我的所有活动设置了背景颜色,其中所有背景都是白色的。背景在 运行 设备 color/window_background pre-marshmallow 上仍然是 color/window_background。
任何人都知道如何在 Android 6 上使这项工作(或为什么它不工作)?
使用更多信息进行编辑:
我的目标是 API 22,我没有对以前的版本进行任何更改或升级 API,只是 Android 6 上的 运行 更改了背景。
我还没有发现任何特定于 Marshmallow 的东西会导致这种情况。所以我的建议是:
正在将背景颜色资源更改为可绘制形状资源。
发件人:
<item name="android:windowBackground">@color/window_background</item>
收件人:
<item name="android:windowBackground">@drawable/window_background</item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/window_background"/>
</shape>
如果您还没有检查所有视图的不透明度:
Make sure your windowBackground actually is the background of most of
your Activity (particularly over scrollable sections where overdraw
is the most important to avoid), removing opaque view backgrounds
where possible.
Make your windowBackground work for you instead of using null
我认为这很有趣,可以看到背景层设置的优先级。我不确定您是否设置了任何视图背景或您如何设置您的应用程序,但这值得一读。
Backgrounds consist of several layers, from back to front:
- the background Drawable of the theme
- a solid color (set via setColor(int))
- two Drawables, previous and current (set via setBitmap(Bitmap) or setDrawable(Drawable)), which may be in transition
我找不到 Marshmallow 中的主题或元素顺序是否有差异,似乎没有根本性的变化,我找不到任何错误。
希望对你有帮助,告诉我,我再看看。
如果这没有帮助,可能值得发布更多与该问题相关的代码。干杯。
我曾经有过同样的问题,但我通过尝试发现如果我在我的样式中评论 actionBarTheme
,它突然开始起作用了。我深入研究了我的样式,发现操作栏的样式在注释掉后设置了一个 android:background
属性,现在一切正常。
如果您使用的是 Android Studio 1.4 或更高版本,请转到主题所在的样式,然后单击右上角的 "Open Editor"。然后在那里更改您的 window 背景。它应该在 "android:colorBackground"
下
如何同时设置 windowBackground
和 colorBackground
<item name="android:windowBackground">@color/window_background</item>
<item name="android:colorBackground">@color/window_background</item>
我已经使用以下元素为我的应用程序定义了一个基本样式:
<item name="android:windowBackground">@color/window_background</item>
在我在 Android 6 上测试我的应用程序之前,它已经为我的所有活动设置了背景颜色,其中所有背景都是白色的。背景在 运行 设备 color/window_background pre-marshmallow 上仍然是 color/window_background。
任何人都知道如何在 Android 6 上使这项工作(或为什么它不工作)?
使用更多信息进行编辑: 我的目标是 API 22,我没有对以前的版本进行任何更改或升级 API,只是 Android 6 上的 运行 更改了背景。
我还没有发现任何特定于 Marshmallow 的东西会导致这种情况。所以我的建议是:
正在将背景颜色资源更改为可绘制形状资源。
发件人:
<item name="android:windowBackground">@color/window_background</item>
收件人:
<item name="android:windowBackground">@drawable/window_background</item>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@color/window_background"/>
</shape>
如果您还没有检查所有视图的不透明度:
Make sure your windowBackground actually is the background of most of your Activity (particularly over scrollable sections where overdraw is the most important to avoid), removing opaque view backgrounds where possible.
Make your windowBackground work for you instead of using null
我认为这很有趣,可以看到背景层设置的优先级。我不确定您是否设置了任何视图背景或您如何设置您的应用程序,但这值得一读。
Backgrounds consist of several layers, from back to front:
- the background Drawable of the theme
- a solid color (set via setColor(int))
- two Drawables, previous and current (set via setBitmap(Bitmap) or setDrawable(Drawable)), which may be in transition
我找不到 Marshmallow 中的主题或元素顺序是否有差异,似乎没有根本性的变化,我找不到任何错误。
希望对你有帮助,告诉我,我再看看。
如果这没有帮助,可能值得发布更多与该问题相关的代码。干杯。
我曾经有过同样的问题,但我通过尝试发现如果我在我的样式中评论 actionBarTheme
,它突然开始起作用了。我深入研究了我的样式,发现操作栏的样式在注释掉后设置了一个 android:background
属性,现在一切正常。
如果您使用的是 Android Studio 1.4 或更高版本,请转到主题所在的样式,然后单击右上角的 "Open Editor"。然后在那里更改您的 window 背景。它应该在 "android:colorBackground"
下如何同时设置 windowBackground
和 colorBackground
<item name="android:windowBackground">@color/window_background</item>
<item name="android:colorBackground">@color/window_background</item>