2010-11-15 3 views
7

Я разрабатываю приложение для Android, и я хочу изменить цвет и тему приложения. Как я могу это сделать?Как изменить тему в приложении для Android?

+5

+1, как это хороший вопрос, но поиск Google будет уже дал вам ответ за меньшее время, чем потребовалось написать вопрос – Basic

+0

Связанный: [как изменить тему во время выполнения] (http://stackoverflow.com/questions/2482848/how-to-change-current-theme-at-runtime-in-android) – rds

ответ

9

Dev guide explains how to apply themes and styles.

Это:

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

Становится это:

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

Определяя XML файл темы:

<?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> 

Вы также можете применить стили для всех ас tivities из приложения:

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

Или только одна активность:

<activity android:theme="@android:style/Theme.Dialog"> 
3
public class MainActivity extends Activity { 
     @Override 
     public void onCreate(Bundle icicle) { 
      setTheme(); // Put the resId as the parameter 
      super.onCreate(icicle); 
    } 
} 
Смежные вопросы