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

 

One Comment

  1. Jan Bos July 6, 2015 at 4:11 pm

    Thank you

     

Leave a Reply

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

 

 

 

Theme by HermesThemes

Copyright © 2018 CoderzHeaven. All Rights Reserved

Please wait...

Subscribe to our newsletter

Want to be notified when our article is published? Enter your email address and name below to be the first to know.