我想在另一个活动之上创建一个透明的活动。
我怎样才能做到这一点呢?
我想在另一个活动之上创建一个透明的活动。
我怎样才能做到这一点呢?
当前回答
在onCreate函数中,在setContentView的下面,添加这一行:
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
其他回答
只需将下面一行添加到清单文件中的activity标记中,它需要看起来透明。
android:theme="@android:style/Theme.Translucent"
我在2.3.3上通过添加android:theme="@android:style/ theme来实现它。半透明的”在活动标签在清单。
我不知道更低的版本……
我想补充一点,因为我也是一个新的Android开发人员。公认的答案很好,但我确实遇到了一些麻烦。我不确定如何在colors.xml文件中添加颜色。下面是应该怎么做:
colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="class_zero_background">#7f040000</color>
<color name="transparent">#00000000</color>
</resources>
在我最初的colors.xml文件中,我有标签“drawable”:
<drawable name="class_zero_background">#7f040000</drawable>
所以我对颜色也这样做了,但我不理解“@color/”引用意味着在XML中寻找标记“color”。我想我也应该提到这一点,以帮助其他人。
在manifest中像这样声明你的活动:
<activity
android:name=".yourActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
并在布局中添加透明背景。
将半透明主题分配给你想要在项目的Android清单文件中透明的活动:
<activity
android:name="YOUR COMPLETE ACTIVITY NAME WITH PACKAGE"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />