

These are the import statements for the various classes and interfaces used in your app. We’ll go through the code in sections and highlight some of the most important points. Now comes the tough bit: implementing the actual functionality! Open the MainActivity.java file in the src/package directory. I agree to the terms and conditions MainActivity.java Open res/values/strings.xml and add the following: Black Open your layout file and enter the following: Īs you’ve probably already noticed, the layout references several strings. We’ll also give the user a way of toggling between the themes and of course, let them know that the app has this option in the first place! To check that the theme switching functionality is working, we’ll create a layout that highlights changes of text and background color.

In this tutorial, we’ll create two themes that define different background colors and text colors: Whether you’re working with ‘themes.xml’ or ‘styles.xml,’ custom themes are defined in the following steps:ġ) Add the opening and closing ‘resources’ tags: Ģ) Give your theme a unique name, and add the closing ‘style’ tag: ģ) Define the visual aspects of your theme using pairs of XML attributes and values: #000000 To create a ‘themes.xml’ file, right click and select ‘New’ followed by ‘Android XML File.’ You can define themes in ‘styles.xml’ or if you want to keep your themes and styles separate you can create a dedicated themes file.

When you create an Android project, Eclipse automatically generates a ‘styles.xml’ file in the res/layout folder. The Android platform includes some pre-defined themes, but it’s easy to create your own so we’ll jump straight into defining a custom theme. A style is a set of formatting rules applied to a View.

