How To Use Build-in Android Themes In Your Application

This example shows how you can apply built-in themes in your application.

Algorithm:

1.) Create a new project by File-> New -> Android Project name it BuiltInThemeExample.

2.) Write following into main.xml:

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Built-In Dialog Theme" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="using Android's Theme.Dialog" />

</LinearLayout>

 

3.) Write following into your manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.builtinthemeexample"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Dialog" >
<activity
android:name="com.example.builtinthemeexample.BuiltInThemeExampleActivity"
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>

 

4.) Run for output.

Steps:

1.) Create a project named BuiltInThemeExample and set the information as stated in the image.

Build Target: Android 4.4
Application Name: BuiltInThemeExample
Package Name: com.example.BuiltInThemeExample
Activity Name: BuiltInThemeExampleActivity

UsingCustomTheme1

2.) Open BuiltInThemeExampleActivity.java file and write following code there:

 

package com.example.builtinthemeexample;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;

public class BuiltInThemeExampleActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.using_custom_theme, menu);
return true;
}
}

 

3.) Compile and build the project.

Output

UsingCustomTheme2