我想在另一个活动之上创建一个透明的活动。

我怎样才能做到这一点呢?


当前回答

它是这样的:

<activity android:name=".usual.activity.Declaration" android:theme="@android:style/Theme.Translucent.NoTitleBar" />

其他回答

对于对话活动,我使用这个:

getWindow().getDecorView().setBackgroundResource(android.R.color.transparent);

但是你也需要将活动中的主视图设置为不可见。否则,背景将是不可见的,而其中的所有视图将是可见的。

它是这样的:

<activity android:name=".usual.activity.Declaration" 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。

在manifest中像这样声明你的活动:

 <activity   
     android:name=".yourActivity"    
     android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>

并在布局中添加透明背景。

只要让活动背景图像是透明的。或者在XML文件中添加主题:

<activity android:name=".usual.activity.Declaration" android:theme="@android:style/Theme.Translucent.NoTitleBar" />