In this android example we learn, how to set 100% Transparent background to make our app more attractive or give special look.its very easy and simple to set Transparent background. in this example we no needed java code.
Let's fun with code:
Step 1: Write code into 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/imageView1"
android:layout_centerHorizontal="true"
android:text="Androidapplink"
android:textAppearance="?android:attr/textAppearanceLarge" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="193dp"
android:src="@drawable/ic_launcher" />
</RelativeLayout>
Set Manifest theme as shown Below:
Step 2: Write code into mainActvity.java
package dev.androidapplink.transparentbackgroungapp;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Step 3: Define theme in AndroidManifest.xml, that is very important to make Transparent background.
- Set below theme if you using minimum API level 8:
android:theme="@android:style/Theme.Translucent
- Set below theme if you using minimum API level 19:
android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor
The AndroidManifest.xml like below:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="dev.androidapplink.transparentbackgroungapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="23" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="dev.androidapplink.transparentbackgroungapp.MainActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent">
<!--
if you want to use android minimum SDK version 19 is required that given below. android:theme="@android:style/Theme.DeviceDefault.Light.NoActionBar.TranslucentDecor"
-->
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Step 4: Run Your Project:
No comments :
Post a Comment