gpt4 book ai didi

android - Android API 18 中的 windowContentOverlay 发生了什么?

转载 作者:IT老高 更新时间:2023-10-28 21:58:42 27 4
gpt4 key购买 nike

将手机升级到 Android 4.3 后,我注意到操作栏下方的阴影不再显示。在我的应用中,我使用 windowContentOverlay 获得了自定义阴影:

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

它一直在显示,但现在它已在 API 18 上消失。从主题中删除该行不会改变任何内容。而在其他 API 版本上,它会显示默认的轻微阴影。

其他人注意到这个问题吗?

最佳答案

我可以通过将以下方法添加到我的基础 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));
}
}
}
}
}

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

关于android - Android API 18 中的 windowContentOverlay 发生了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17945785/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com