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

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


当前回答

你可以从你的活动中删除setContentView(r.b ayout. mlayout),并设置主题为android:theme="@style/AppTheme.Transparent"。查看这个链接了解更多细节。

其他回答

只需将下面一行添加到清单文件中的activity标记中,它需要看起来透明。

android:theme="@android:style/Theme.Translucent"

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

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

你可以从你的活动中删除setContentView(r.b ayout. mlayout),并设置主题为android:theme="@style/AppTheme.Transparent"。查看这个链接了解更多细节。

我发现的最简单的方法是在AndroidManifest中设置活动的主题为android:theme="@android:style/ theme . holo . dialog "。

然后在活动的onCreate方法中,调用getWindow()。setBackgroundDrawable(新ColorDrawable(0));。

如果你正在使用AppCompatActivity,那么在styles.xml中添加这个

<style name="TransparentCompat" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <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>

在清单文件中,您可以像这样将此主题添加到活动标签

android:theme="@style/TransparentCompat"

更多细节请阅读这篇文章