2010-11-15 24 views
7

Ben bir Android uygulaması geliştiriyorum ve uygulama rengini ve temasını değiştirmek istiyorum. Bunu nasıl yapabilirim?Bir Android uygulamasında temayı nasıl değiştiririm?

+5

+1 o iyi bir soru ama aldı daha google arama daha kısa sürede bir cevap verdi etmezdi sorusunu – Basic

+0

İlgili yazmak için: [zamanında temasını nasıl değiştirileceği] (http://stackoverflow.com/questions/2482848/how-to-change-current-theme-at-runtime-in-android) – rds

cevap

9

Dev guide explains how to apply themes and styles.

Bu:

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

Ayrıca tüm ac stiller uygulayabilirsiniz: bir xml tema dosyasını tanımlayarak

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

:

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

bu Oluyor Bir uygulamanın tivities:

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

Ya sadece bir aktivite:

<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); 
    } 
} 
İlgili konular