2010-03-30 19 views
6

Ne yaptığımı bilmiyorum ama bir süredir TabWidget'im gerçekten güzel görünen beyaz renkli sekmelere sahipti. Projemde hiç bir tema veya arka plan/ön plan rengi koymadım. Bir sonraki derlememde gri sekmelere geri döndü. Uygulamam varsayılan koyu temayı kullanıyor. Uygulama temasını ışıklandırmasına rağmen, sekmeler hala gri. Açıkçası sekmelerin rengini değiştiren başka bir şeydi. Bunu nasıl yapacağını bilen var mı?TabWidget beyaz ön plan rengi?

+0

test ediyorsunuz? Sekme stili 2.0 olarak değiştirildi. Ayrıca, 'DDMS' ile çekilen bir ekran görüntüsü gönderirseniz çok yardımcı olur. –

+0

Ah, evet. 1.6 için derleme yapıldı. Aynı rengi 2.0+ için manuel olarak ayarlamanın herhangi bir yolu var mı? – Monstieur

+0

Bu sorunu yaşadım ve AndroidManifest.xml dosyasındaki "targetSdkVersion" özniteliğinin benim için değişmesine neden olduğunu belirledim. –

cevap

15

I Android 1.6'nın ışık temasında bir hata nedeniyle bir sorun yaşıyordu (sekme gösterge metni beyaz).

styles.xml: Sonra

<style name="MyTheme" parent="@android:style/Theme.Light"> 
    <item name="android:tabWidgetStyle">@style/LightTabWidget</item> 
</style> 

<style name="LightTabWidget" parent="@android:style/Widget.TabWidget"> 
    <!-- set textColor to red, so you can verify that it applied. --> 
    <item name="android:textColor">#f00</item> 
</style> 

Sadece bu tema uygulamak

  1. varsayılan tema miras özel bir tema oluşturdu şu şekildedir: Varsayılan temanın üstüne başardı benim android:theme="@style/MyTheme" ekleyerek benim uygulama için AndroidManifest.xml benim <application /> öğeye ekleyerek. dinleyici daha public void onCreate(Bundle savedInstanceState)

      `tabHost = getTabHost(); 
          tabHost.setOnTabChangedListener(this); 
        tabHost.setCurrentTab(0); 
        setTabColor();` 
    

    içinde

+0

thanx steve, bu bana yardımcı oldu ve sen benim hayatımı yaptın –

1

:

public void (String tabid) { setTabColor() onTabChanged;

nihayet ön plan ve arka plan ayarlamak çok fonksiyonlu,: onCreated() in

public void setTabColor() { 
    // set foreground color: 
    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { 
     RelativeLayout rl = (RelativeLayout) tabHost.getTabWidget().getChildAt(i); 
     ImageView imageView = (ImageView) rl.getChildAt(0);// change it if you want it 
     TextView textView = (TextView) rl.getChildAt(1);//   
     textView.setTextColor(Color.parseColor("#FFFFFF")); 
    } 

    // set background color: 
    for (int i = 0; i < tabHost.getTabWidget().getChildCount(); i++) { 
     tabHost.getTabWidget().getChildAt(i).setBackgroundColor(Color.parseColor("#010101")); // unselected 
    } 
    tabHost.getTabWidget().getChildAt(tabHost.getCurrentTab()).setBackgroundColor(Color.parseColor("#121288")); // selected 
} 
0

: belki platformunun iki farklı sürümlerinde

tabHost.setCurrentTab(0); 

// Set tabs text color to white: 
TabWidget tabWidget = tabHost.getTabWidget(); 
int whiteColor = getResources().getColor(R.color.white); 
int someOtherColor = getResources().getColor(R.color.someOtherColor); 
for(int i = 0; i < tabWidget.getChildCount(); i++){ 
    View tabWidgetChild = tabWidget.getChildAt(i); 
    if(tabWidgetChild instanceof TextView){ 
     ((TextView) tabWidgetChild).setTextColor(whiteColor); 
    } else if(tabWidgetChild instanceof Button){ 
     ((Button) tabWidgetChild).setTextColor(whiteColor); 
    } else if(tabWidgetChild instanceof ViewGroup){ 
     ViewGroup vg = (ViewGroup)tabWidgetChild; 
     for(int y = 0; y < vg.getChildCount(); y++){ 
      View vgChild = vg.getChildAt(y); 
      if(vgChild instanceof TextView){ 
       ((TextView) vgChild).setTextColor(whiteColor); 
      } 
     } 
     vg.setBackgroundColor(someOtherColor); 
    } 
}