问题描述
<style name="Sidemenu" parent="Usual">
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:colorBackgroundCacheHint">@null</item>
</style>
它一直在完美运行。像往常一样,您可以看到下面的活动。
但是我只是将 Android Studio 更新到 4.2RC1 ..
现在..它不起作用!
下方区域为黑色。
完全神秘。
周围有什么解决方案吗?
解决方法
感谢几年前出现过类似问题的惊人旧帖子:https://stackoverflow.com/a/35915764/294884
4.2RC1 解决方法:
(1) 这是另一个机器人活动/主题错误
(2) 在清单中,您必须将主题设置为 Theme.AppCompat.Dialog
// side menu
<activity android:name=".. LeftMenu" android:theme="@style/Theme.AppCompat.Dialog" />
<!-- beware of insane droid transparent activity bug... -->
(3) 只有在代码中,你才能把主题设置成你的主题。 (在超级之前这样做)
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.YourTransparentTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.aty_leftmenu);
}
(4) 你自己的风格主题是:
<style name="YourTransparentTheme" parent="YourGeneralTheme">
<item name="android:windowBackground">@android:color/transparent</item>
.. and other colors etc you desire ..
</style>
为什么只需要 windowBackground 的详细信息: https://stackoverflow.com/a/67040753/294884
总而言之,该错误的解决方法是:
必须在清单中设置 Theme.AppCompat.Dialog。您只能在 onCreate 中设置自己的样式。
(旁白:请注意,如果您的大多数 Activity 都有标题栏(因此基于 Theme.AppCompat.Light),则没有问题,但是您的透明 Activity 没有标题栏(因此基于 Theme.AppCompat.Light。 NoActionBar)。通过这种方式,您可以使用通常的“左侧菜单”或类似内容也覆盖主应用程序的标题栏。)