How to create a custom theme and use it in android application

Android – How to create the custom Android theme. let’s see how to create the custom material design theme as you want for your enterprise application. you can be used you custom color as you want on your application so let’s see how to customize the application background and font color as you want.

So let’s starts first of open your colors configuration file from “res/values/colors.xml” file and change or add the color as you want. My colorĀ configuration file as below.

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#3F51B5</color>
    <color name="colorPrimaryDark">#303F9F</color>
    <color name="colorAccent">#FF4081</color>
    <color name="colorText">#FFFFFF</color>
</resources>

Then after creating the new theme configuration file at “res/values/themes.xml” for creating new theme configuration like below.

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="MyTheme" parent="Theme.AppCompat.Light">

        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="android:windowBackground">@color/colorAccent</item>
        <item name="android:textColorPrimary">@color/colorText</item>

    </style>

</resources>

The above is my theme configuration I set the “colorPrimary”, “colorPrimaryDark”, “android:windowBackground”, “android:textColorPrimary” for customize the App screen as i want.

The third step applies theme on your activity so let’s see first open “AndroidManifest.xml” file and change your custom configuration file like below.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.thecodingstuff.background">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity" android:theme="@style/MyTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

As per above file, I add my custom theme on main activity like ‘ android:theme=”@style/MyTheme” ‘ You can add your custom theme on your activity for changing the app theme.

So you can customize the App background and font color as you want using the themes configuration.

If you face any issue after using this code please write the comment below.