How do I create a transparent Activity on Android?
Add the following style in your res/values/styles.xml
file (if you don’t have one, create it.) Here’s a complete file:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">@android:color/transparent</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
</style>
</resources>
(The value @color/transparent
is the color value #00000000
which I put in the res/values/color.xml
file. You can also use @android:color/transparent
in later Android versions.)
Then apply the style to your activity, for example:
<activity android:name=".SampleActivity" android:theme="@style/Theme.Transparent">
...
</activity>
How to create transparent activity in android?
There are two ways to achieve this
- use the following theme for activity.
android:theme="@android:style/Theme.Translucent"
- Set background of the activity as a trans parent png image or a transparent code
eg.
android:background="@drawable/transparent_bg"
or
android:background="#33BBFFFF"
this is a semi transparent color
Related Links
How to make a background 20% transparent on Android
Understanding colors on Android (six characters)
- To dismiss activity on tap implement onTouchListener and when touch event is detected call finish();
Hope it helps !!
How to display transparent activity on the another activity without removing previous activity
declare your activity in manifest like this
<activity android:name=".yourActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen"/>
and add a transperent background to your layout
like this
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background = "any tranparent image name" >
</RelativeLayout>
Edit:
i think you are using this to open your transparent activity it finish your previous activity
Intent intent =new Intent(mContext,yourNewActivity.class);
startActivity(intent);
finish();
remove finish from here then your new activity in on top of previous activity like this
Intent intent =new Intent(mContext,yourNewActivity.class);
startActivity(intent);
Hope help..
Activity with transparent background
After setting LinearLayout transparency try to set it's child transparency to the value that you want.
This should make them have different transparency than LinearLayout. Try it.
Is there a way to make an activity transparent in Android Studio?
You can achieve this through multiple ways
Create an activity and make its background as transparent in the layout.(Not recommended)
Create an alert dialog within the activity and make the alert dialog background as transparent
Create a dialog fragment make its layout transparent and open it from the activity.
Create a view stub within the same activity layout and inflate the view when required. (Handling back press events might be a difficult task here).
Although the right way would be to create an alert dialog within the activity or creating a dialog fragment or create a view stub. Create an alert dialog if you don't have much events or elements within the dialog since its easy and efficient than creating a dialog fragment for a little dialog. Creating a view stub would be the most efficient way since it simply inflates the view which takes less amount of resource. But don't go with creating an activity for this dialog which is resource intensive and not the correct way.
How do you create a transparent activity that can overlay the home screen but is not dismissed when the home or back button is pressed?
You can create a transparent activity with the help of
Make the background of layout in your xml file transparent by using
android:background="@android:color/transparent
And also, make the theme in your manifest file transparent for that particular activity
<activity
android:name="Your activity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar.Fullscreen">
</activity>And for back press override the
onBackPressed()
method and removesuper.onBackPressed()
@Override
public void onBackPressed()
{
// TODO Auto-generated method stub
}
Android: how to create a transparent dialog-themed activity
You can create a tranparent dialog by this.
public class DialogActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle(" ");
alertDialog.setMessage("");
alertDialog.setIcon(R.drawable.icon);
alertDialog.setButton("Accept", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.setButton2("Deny", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
}
});
alertDialog.show();
}
}
After this just put a line in AndroidManifest.xml, where you define your activity in manifest.
android:theme="@android:style/Theme.Translucent.NoTitleBar"
Related Topics
Jdbc VS Web Service For Android
How to Change the Status Bar Color in Android
Retrieve a Fragment from a Viewpager
How Exactly Does the Android:Onclick Xml Attribute Differ from Setonclicklistener
Find Location of a Removable Sd Card
Install Application Programmatically on Android
How to Use External Jars in an Android Project
How to Copy Files from 'Assets' Folder to Sdcard
Difference Between Gravity and Layout_Gravity in Android
How to Get Ip Address of the Device from Code
Android: Install .Apk Programmatically
How to Correctly Save Instance State of Fragments in Back Stack
Why Does an Image Captured Using Camera Intent Gets Rotated on Some Devices on Android
How to Add Parameters to Httpurlconnection Using Post Using Namevaluepair
Sending and Parsing Json Objects in Android
How to Enable Multidexing With the New Android Multidex Support Library