29

After upgrading my phone to Android 4.3 I noticed the shadow below the actionbar is not showing anymore. In my app I've got a custom shadow using windowContentOverlay:

<item name="android:windowContentOverlay">@drawable/shadows_bottom</item>

It's always been showing but now it's gone on API 18. Removing that line from the theme doesn't change anything. while on other API versions it shows a default slight shadow.

Anyone else has noticed that issue?

4

2 回答 2

30

通过将以下方法添加到我的基础并在布局膨胀后FragmentActivity调用它,我能够解决这个平台错误:onCreate

/**
 * 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));
                }
            }
        }
    }
}

这很好用,因为您不必更改主题或动态地将视图添加到布局中。它应该是向前兼容的,并且一旦修复了这个错误就可以很容易地删除。

于 2013-08-07T03:01:16.207 回答
18

这是正式的错误,将在下一个平台版本中修复: https ://code.google.com/p/android/issues/detail?id=58280

更新:这似乎已在 API 级别 19 上修复

于 2013-08-06T18:45:29.863 回答