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>
To apply theme for a particular activity, open AndroidManifest.xml file and modify the code in the activity tag like as shown below.
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.
Structure of the Project: