我想在另一个活动之上创建一个透明的活动。
我怎样才能做到这一点呢?
我想在另一个活动之上创建一个透明的活动。
我怎样才能做到这一点呢?
当前回答
在styles.xml中:
<style name="Theme.AppCompat.Translucent" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">#33000000</item> <!-- Or any transparency or color you need -->
<item name="android:windowNoTitle">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:colorBackgroundCacheHint">@null</item>
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowAnimationStyle">@android:style/Animation</item>
</style>
在AndroidManifest.xml中:
<activity
android:name=".WhateverNameOfTheActivityIs"
android:theme="@style/Theme.AppCompat.Translucent">
...
</activity>
其他回答
将半透明主题分配给你想要在项目的Android清单文件中透明的活动:
<activity
android:name="YOUR COMPLETE ACTIVITY NAME WITH PACKAGE"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
我发现的最简单的方法是在AndroidManifest中设置活动的主题为android:theme="@android:style/ theme . holo . dialog "。
然后在活动的onCreate方法中,调用getWindow()。setBackgroundDrawable(新ColorDrawable(0));。
所有这些答案可能会让人困惑,透明活动和无UI活动之间是有区别的。
用这个:
android:主题= " @android:风格/ Theme.Translucent.NoTitleBar”
将使活动透明,但将阻塞UI。
如果你想要一个None的UI活动,请使用这个:
android:主题= " @android:风格/主题。NoDisplay”
为它指定半透明主题
android:theme="@android:style/Theme.Translucent.NoTitleBar"
2021年的事实
只需添加
<item name="android:windowBackground">@android:color/transparent</item>
你就完成了。
windowIsFloating错误,这使得INSET浮动窗口。
windowcontenttoverlay只与阴影相关。
windowwistranslucent是错误的,它没有使它,所以你可以看到背后的活动。windowIsTranslucent只适用于动画转换。
backgroundDimEnabled使下面的活动变暗,但是,它在不同的设备上是完全错误的。(在某些情况下,除非你使用windowisfloat,否则它什么也不做;总的来说,这种行为是完全错误的/不确定的。)
colorBackgroundCacheHint是无关紧要的,除非在非常旧的设备上,默认是null。