2010-11-15 52 views
7

我正在開發一個Android應用程序,我想改變應用程序的顏色和主題。我怎樣才能做到這一點?如何更改Android應用程序的主題?

+5

+1,因爲它是一個很好的問題,但谷歌搜索就已經給你一個答案在較短的時間比花編寫問題 – Basic 2010-11-15 22:10:15

+0

相關:[如何在運行時更改主題](http://stackoverflow.com/questions/2482848/how-to-change-current-theme-at-runtime-in-android) – rds 2013-01-20 11:44:06

回答

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); 
    } 
} 
相關問題