我将我的手机升级到Android 4.3后,发现操作栏下的阴影不再显示。在我的应用程序中,我使用windowContentOverlay
自定义了一个阴影:
<item name="android:windowContentOverlay">@drawable/shadows_bottom</item>
一直在显示的内容,在API 18上突然消失了。从主题中移除该行并没有改变任何东西。而在其他API版本上,它会显示一个默认的轻微阴影。
还有其他人注意到这个问题吗?
我将我的手机升级到Android 4.3后,发现操作栏下的阴影不再显示。在我的应用程序中,我使用windowContentOverlay
自定义了一个阴影:
<item name="android:windowContentOverlay">@drawable/shadows_bottom</item>
一直在显示的内容,在API 18上突然消失了。从主题中移除该行并没有改变任何东西。而在其他API版本上,它会显示一个默认的轻微阴影。
还有其他人注意到这个问题吗?
我能够通过在我的基础FragmentActivity
中添加以下方法并在布局被填充后在onCreate
中调用它来解决这个平台的bug:
/**
* Set the window content overlay on device's that don't respect the theme
* attribute.
*/
private void setWindowContentOverlayCompat() {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.JELLY_BEAN_MR2) {
// Get the content view
View contentView = findViewById(android.R.id.content);
// Make sure it's a valid instance of a FrameLayout
if (contentView instanceof FrameLayout) {
TypedValue tv = new TypedValue();
// Get the windowContentOverlay value of the current theme
if (getTheme().resolveAttribute(
android.R.attr.windowContentOverlay, tv, true)) {
// If it's a valid resource, set it as the foreground drawable
// for the content view
if (tv.resourceId != 0) {
((FrameLayout) contentView).setForeground(
getResources().getDrawable(tv.resourceId));
}
}
}
}
}
这样做非常好,因为您不需要更改主题或动态添加视图到布局中。它应该是向前兼容的,并且一旦修复了此错误,可以轻松地将其删除。
这是一个正式的漏洞,将在下一平台发布时进行修复: https://code.google.com/p/android/issues/detail?id=58280
更新: API 19 级别已经修复了此问题。