Android Theme Demo Example
Android Sample Codes Uncategorized

Android Theme Demo Example

This is a tutorial on usage of theme in android app. We can apply theme to a specific activity or apply to the whole app.

We have already discussed the tutorial on style usage in android. Styles on Android allow you to separate your app design from the UI structure and behavior, similar to style sheets usage in web design. That is we can separate the design of our app from the structure of the app.

This Android theme demo example tutorial teaches you the steps for how to apply theme to your android app.

Android Theme Demo

If we want to apply a theme to all activities within our app. Instead of applying the style to a individual view, you can apply a collection of styles as a Theme to an Activity or application.

Once you know your colors, you can update the values in res/values/colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="colorPrimary">#008577</color>
    <color name="colorPrimaryDark">#00574B</color>
    <color name="colorAccent">#D81B60</color>
</resources>

Following is the example of defining a theme in android application. Create a themes.xml file in res/values that references that color.

<resources>
    <!-- Base application theme. -->
    <style name="CustomTheme" parent="Theme.AppCompat.Light">
        <item name="android:windowBackground">@color/colorPrimary</item>
        <item name="android:colorBackground">@color/colorAccent</item>
    </style>
</resources>

The above code overrides windowBackground and colorBackground properties of Theme.AppCompat.Light theme.

To apply theme for a particular activity, open AndroidManifest.xml file and modify the code in the activity tag like as shown below.

<activity android:theme="@style/CustomTheme"> 

To set the theme for all the activities in android application, open AndroidManifest.xml file and modify the code in the application tag like as shown below.

<application android:theme="@style/CustomTheme">

Structure of the Project:

Android Theme Demo Example

Leave a Reply

Your email address will not be published.