2011-12-12 37 views
0

我正在爲我的Android應用創建一些自定義選項卡,但是設計者在頂部設計了帶有小曲線的選項卡。所以,在這些曲線之間應該有「透明」的顏色。是否可以更改TabHost/Widget背景顏色?或者至少應用程序背景

製作曲線並不困難,但問題是,代替透明背景顏色,選項卡主機顯然具有主題背景顏色(在我的情況下爲白色)。

我不認爲有可能做一個透明的背景顏色,因爲屏幕內容高於(在我的情況下)的標籤。第二個選擇是將tab內容的某些像素「移動」到tabWidget的頂部,但似乎也不可行。最後的替代方案是,讓應用程序的背景顏色與默認的應用程序背景顏色相匹配或使用可繪製的背景顏色會很好。

如果有這些可能的事情?

如果不是,最壞的情況是簡單地將該背景顏色放到每個選項卡;就是想。

謝謝!

+0

製表符的一個快照值多於1000個單詞。 –

回答

1

你好,我希望它可以幫助你。

@Override 
public void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.tab); 

    host = getTabHost(); 

     host.addTab(host.newTabSpec(Constants.TAG_TAB1).setIndicator(Constants.TAG_TAB1,getResources().getDrawable(R.drawable.img1)).setContent(new Intent(this, Activity1.class))); 
    host.addTab(host.newTabSpec(Constants.TAG_TAB2).setIndicator(Constants.TAG_TAB2,getResources().getDrawable(R.drawable.img2)).setContent(new Intent(this, Activity2.class); 
    host.addTab(host.newTabSpec(Constants.TAG_TAB3).setIndicator(Constants.TAG_TAB3,getResources().getDrawable(R.drawable.img3)).setContent(new Intent(this, Activity3.class))); 
    host.addTab(host.newTabSpec(Constants.TAG_TAB4).setIndicator(Constants.TAG_TAB4,getResources().getDrawable(R.drawable.img4)).setContent(new Intent(this, Activity4.class))); 

     host.setCurrentTab(0); 


     for(int i=0;i<host.getTabWidget().getChildCount();i++) 
     { 
      host.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_bg); 
     } 
     host.getTabWidget().getChildAt(host.getCurrentTab()).setBackgroundResource(android.R.color.transparent);// selected 

    host.setOnTabChangedListener(this); 
} 


    @Override 
    public void onTabChanged(String tabId) 
    { 

     for(int i=0;i<host.getTabWidget().getChildCount();i++) 
     { 
      host.getTabWidget().getChildAt(i).setBackgroundResource(R.drawable.tab_bg); 
    } 
     host.getTabWidget().getChildAt(host.getCurrentTab()).setBackgroundResource(android.R.color.transparent);// selected 

    }