我想在另一个活动之上创建一个透明的活动。
我怎样才能做到这一点呢?
我想在另一个活动之上创建一个透明的活动。
我怎样才能做到这一点呢?
当前回答
只需将下面一行添加到清单文件中的activity标记中,它需要看起来透明。
android:theme="@android:style/Theme.Translucent"
其他回答
只需将下面一行添加到清单文件中的activity标记中,它需要看起来透明。
android:theme="@android:style/Theme.Translucent"
我只做了两件事,它让我的活动变得透明。它们在下面。
在清单文件中,我只是在活动标记中添加了以下代码。 android:主题= " @android:风格/ Theme.Translucent.NoTitleBar.Fullscreen” 然后我将该活动的主布局的背景设置为“#80000000”。就像 android:背景= " # 80000000 "
它非常适合我。
在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:theme="@android:style/Theme.Translucent.NoTitleBar"
我发现的最简单的方法是在AndroidManifest中设置活动的主题为android:theme="@android:style/ theme . holo . dialog "。
然后在活动的onCreate方法中,调用getWindow()。setBackgroundDrawable(新ColorDrawable(0));。