Wednesday , December 12 2018
Home / Android / Android Transparent Background | Set Opacity in Android | Make android application with transparent background

Android Transparent Background | Set Opacity in Android | Make android application with transparent background

Using this simple code you can make android application background transparent and in other words you can set opacity in background.

Step 1 : In your manifest make that activity theme to Translucent-

<activity
android:name=“com.w2class.transparent.background.MainActivity”
android:theme=“@android:style/Theme.Translucent”
android:label=“@string/app_name” >

Step 2 : Now your page will be 100% transparent, so if you need some background color then set opacity like-

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“#80000000″
tools:context=“.MainActivity” >
And below is the whole code-
1)    MainActivity.java
package com.w2class.transparent.background;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

}

2)  Activity_main.xml

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”
xmlns:tools=“http://schemas.android.com/tools”
android:layout_width=“match_parent”
android:layout_height=“match_parent”
android:background=“#8C000000″
tools:context=“.MainActivity” >

<TextView
android:id=“@+id/textView1″
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_centerHorizontal=“true”
android:layout_centerVertical=“true”
android:text=“www.w2class.com\n(From: Peeyush Singhal)”
android:textColor=“#FFFFFF”
android:textSize=“25sp” />

<ImageView
android:id=“@+id/imageView1″
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:layout_above=“@+id/textView1″
android:layout_alignLeft=“@+id/textView1″
android:src=“@drawable/logo” />
</RelativeLayout>
3)  AndroidManifest.xml

<?xml version=“1.0” encoding=“utf-8″?>
<manifest xmlns:android=“http://schemas.android.com/apk/res/android”
package=“com.w2class.transparent.background”

android:versionCode=“1”
android:versionName=“1.0” >

<uses-sdk
android:minSdkVersion=“8”
android:targetSdkVersion=“18” />

<application
android:allowBackup=“true”
android:icon=“@drawable/logo”
android:label=“@string/app_name”
android:theme=“@style/AppTheme” >

<activity
android:name=“com.w2class.transparent.background.MainActivity”
android:theme=“@android:style/Theme.Translucent”
android:label=“@string/app_name” >
<intent-filter>
<action android:name=“android.intent.action.MAIN” />
<category android:name=“android.intent.category.LAUNCHER” />
</intent-filter>
</activity>
</application>

</manifest>

 

About admin

Check Also

Android Activity Launch Modes

Launch mode is an instruction for Android OS which specifies how the activity should be ...

Leave a Reply