How do I create a transparent Activity on Android?

2018-12-31 00:29发布

I want to create a transparent Activity on top of another activity.

How can I achieve this?

19条回答
爱死公子算了
2楼-- · 2018-12-31 00:56

I achieved it on 2.3.3 by just adding android:theme="@android:style/Theme.Translucent" in the activity tag in the manifest.

I don't know about lower versions...

查看更多
回忆,回不去的记忆
3楼-- · 2018-12-31 00:58

Just let the activity background image be transparent. Or add the theme in the XML file:

<activity android:name=".usual.activity.Declaration" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
查看更多
几人难应
4楼-- · 2018-12-31 00:58

For dialog activity I use this:

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

But you also need to set your main View in the activity to invisible. Otherwise the background will be invisible while all views in it will be visible.

查看更多
无色无味的生活
5楼-- · 2018-12-31 00:58

in addition to the above answers:

to avoid android Oreo related crash on activity

<style name="AppTheme.Transparent" parent="@style/Theme.AppCompat.Dialog">
    <item name="windowNoTitle">true</item>
    <item name="android:windowCloseOnTouchOutside">false</item>
</style>

<activity
     android:name="xActivity"
     android:theme="@style/AppTheme.Transparent" />
查看更多
看风景的人
6楼-- · 2018-12-31 00:59

Declare your activity in the manifest like this:

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

And add a transparent background to your layout.

查看更多
不流泪的眼
7楼-- · 2018-12-31 00:59

Just add the following line to the activity tag in your manifest file that needs to look transparent.

android:theme="@android:style/Theme.Translucent"
查看更多
登录 后发表回答