Apply Custom Theme for your activity in android.

By | February 5, 2012

In today’s tutorial I will show how to apply custom theme for your activity in android.
Android has several built in themes for applying to your activity but you can also provide your own custom themes for your activity.

Now we will start creating an activity with a custom theme applied.
Create a fresh project and name it ThemeActivity.

Now create a file named “styles.xml” in the res/values folder and copy this code into it.

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="custom_theme_color">#b0b0ff</color>
<style name="CustomTheme" parent="android:Theme.Light">
    <item name="android:windowBackground">@color/custom_theme_color</item>
    <item name="android:colorBackground">#ff00ff</item>
</style>
</resources>

Now in the AndroidManifest.xml make changes in the activity tag for the activity you want to apply this theme.

Here I have only one activity which is the main activity for which I am applying the theme.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
      package="com.coderzheaven.pack"
      android:versionCode="1"
      android:versionName="1.0">
    <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/CustomTheme">
        <activity android:name=".ThemeActivityDemo"
                  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>

This is the main java file.

package com.coderzheaven.pack;

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

public class ThemeActivityDemo extends Activity {

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

I am not making any changes in the main.xml.
Now applying theme to this activity is complete and you can now run the project.

Apply theme to your activity

Apply theme to your activity

Website Pin Facebook Twitter Myspace Friendfeed Technorati del.icio.us Digg Google StumbleUpon Premium Responsive

Leave a Reply

Your email address will not be published. Required fields are marked *