Learn how to use the new Android Themes in your App

Newer versions of Android have additional themes available to applications, and you might want to use these while running on those platforms while still being compatible with older versions.  – Android Documentation

Since your app targets devices which run on API level 17 and above you don’t need to provide backward compatibility. You can make use of the new Themes.

Let’s see how.

You are going to change the app so that it uses Theme.Holo.Light by default and switches to Theme.Material.Light if app is running on API level 21.

  1. Open MainActivity class. Change ActionBarActivity to Activity.
  2. You will notice there are two style.xml files. One which supports v21 and other for lower versions (default).

Change default style.xml to use the following parent theme – android.Theme.Holo.Light

Change v21 style.xml to use the following parent theme – android.Theme.Material.Light

Follow the video to understand better. Source Code is available here

Android Basics : Introduction to Themes

In the last Article you created a new App ThemeDemoApp. Let’s refer to this App to understand the Theme.

Currently the Activity class extends ActionBarActivity. This class is used in conjunction with Theme.AppCompat themes to add action bar to apps that support API levels b/w 7 and 10. If you use this as the superclass you have to use one of these Themes or your App won’t run.

For now you can refer to the Manifest and style XML files to see how theme is referred to.

Source Code available here