问题描述
我有一个菜单项活动,出现在另一项活动上.
I have a sidemenu activity which appears over another activity.
<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>
它一直运行良好.正常情况下,您可以在下面看到活动.
It has been working perfectly. As normal, you can see the activity below.
但是我只是将Android Studio更新为4.2RC1 ..
However I simply updated Android Studio to 4.2RC1 ..
现在..它不起作用!
下方区域为黑色.
完全神秘.
有什么解决方案吗?
推荐答案
此惊人的旧帖子由几年前存在类似问题的地方提供:
courtesy this amazing old post where there was a similar problem a few years ago: https://stackoverflow.com/a/35915764/294884
(1)这是另一个机器人活动/主题错误
(1) It's yet another droid activity/theme bug
(2)在清单中,您必须将主题设置为Theme.AppCompat.Dialog
// side menu
<activity android:name=".. LeftMenu" android:theme="@style/Theme.AppCompat.Dialog" />
<!-- beware of insane droid transparent activity bug... -->
(3)仅在代码中,可以将主题设置为主题.(超级之前这样做)
(3) Only in code, can you set the theme to your theme. (Do so before super)
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.YourTransparentTheme);
super.onCreate(savedInstanceState);
setContentView(R.layout.aty_leftmenu);
}
(4)您自己的样式主题为:
(4) Your own theme in styles will be:
<style name="YourTransparentTheme" parent="YourGeneralTheme">
<item name="android:windowBackground">@android:color/transparent</item>
.. and other colors etc you desire ..
</style>
为什么只需要window的详细信息背景: https://stackoverflow.com/a/67040753/294884
总而言之,该错误的解决方法是:
In summary the workaround for the bug is:
(旁边:请注意,如果大多数活动都具有标题栏(因此基于Theme.AppCompat.Light)是没有问题的,但是透明活动没有标题栏(因此基于Theme.AppCompat.Light).NoActionBar).这样一来,您可以拥有通常的情况,其中左菜单"或类似内容也涵盖了主应用程序的标题栏.
(Aside: Note that it is no problem if most of your activities have a title bar (so based on Theme.AppCompat.Light), but your transparent activity has no title bar (so based on Theme.AppCompat.Light.NoActionBar). In that way you can have the usual thing where a "left menu" or similar covers also the title bar of the main app.)
这篇关于更新到4.2RC1,透明活动不起作用?突然黑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!