7

I'm developing an Android application and I want to change the color and theme of the application. How can I do this?

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
Adham
  • 63,550
  • 98
  • 229
  • 344
  • 5
    +1 as it's a good question but a google search would've given you an answer in less time than it took to write the question – Basic Nov 15 '10 at 22:10
  • Related: [how to change theme at runtime](http://stackoverflow.com/questions/2482848/how-to-change-current-theme-at-runtime-in-android) – rds Jan 20 '13 at 11:44

2 Answers2

9

Dev guide explains how to apply themes and styles.

This:

<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:textColor="#00FF00"
    android:typeface="monospace"
    android:text="@string/hello" />

Becomes this:

<TextView
    style="@style/CodeFont"
    android:text="@string/hello" />

By defining an xml theme file:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <style name="CodeFont" parent="@android:style/TextAppearance.Medium">
        <item name="android:layout_width">fill_parent</item>
        <item name="android:layout_height">wrap_content</item>
        <item name="android:textColor">#00FF00</item>
        <item name="android:typeface">monospace</item>
    </style>
</resources>

You can also apply styles to all activities of an application:

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

Or just one activity:

<activity android:theme="@android:style/Theme.Dialog">
Bryan Denny
  • 27,363
  • 32
  • 109
  • 125
3
public class MainActivity extends Activity {
      @Override
      public void onCreate(Bundle icicle) {
          setTheme(); // Put the resId as the parameter
          super.onCreate(icicle);
     }
}