I want to create a transparent Activity on top of another activity.
How can I achieve this?
Note 1:In Drawable folder create test.xml and copy the following code
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke android:width="2dp" />
<gradient
android:angle="90"
android:endColor="#29000000"
android:startColor="#29000000" />
<corners
android:bottomLeftRadius="7dp"
android:bottomRightRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp" />
</shape>
// Note: Corners and shape is as per your requirement.
// Note 2:Create xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/test"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1.09"
android:gravity="center"
android:background="@drawable/transperent_shape"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
Just add the following line to the activity tag in your manifest file that needs to look transparent.
android:theme="@android:style/Theme.Translucent"
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.
You can remove setContentView(R.layout.mLayout)
from your activity and set theme as android:theme="@style/AppTheme.Transparent"
. Check this link for more details.
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...
All those answers might be confusing, there is a difference between Transparent activity and None UI activity.
Using this:
android:theme="@android:style/Theme.Translucent.NoTitleBar"
Will make the activity transparent but will block the UI.
If you want a None UI activity than use this:
android:theme="@android:style/Theme.NoDisplay"