2012-05-02 104 views
0

我想我的自定義選項卡,它類似於下面的圖片..任何知道該怎麼做..如何獲得自定義選項卡

默認情況下,Android的標籤不支持XML設置寬度和高度..任何想法如何做標籤這樣

enter image description here

+0

我沒有看到這裏的任何定製,只是默認的拉片保持... – vtuhtan

回答

0

這是一個tabhost的基本佈局。

下面是一個示例:將其放入將在創建後保留tabhost並擴展TabActivity的活動中。重複你想要的標籤數量。 API演示有助於瞭解這些基本信息。

可繪製圖標將設在繪製文件夾中的XML文件:

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<!-- When selected, use white --> 
<item android:drawable="@drawable/white" 
     android:state_selected="true" /> 
<!-- When not selected, use grey--> 
<item android:drawable="@drawable/grey" /> 

TabHost tabHost = getTabHost(); 

// Tab 1 
TabSpec tab1spec = tabHost.newTabSpec("TAB1 TITLE"); 
tab1spec.setIndicator("TAB1 TEXT", getResources().getDrawable(R.drawable.tab1iconhere)); 
Intent tab1Intent = new Intent(this, ActivityforTab1.class); 
tab1spec.setContent(tab1Intent); 

// Tab 2 
TabSpec tab2spec = tabHost.newTabSpec("TAB2 TITLE"); 
tab2spec.setIndicator("TAB2 TEXT", getResources().getDrawable(R.drawable.tab2iconhere)); 
Intent tab2Intent = new Intent(this, ActivityforTab2.class); 
tab2spec.setContent(tab2Intent); 

// Adding all TabSpec to TabHost 
tabHost.addTab(tab1spec); // Adding tab1 
tabHost.addTab(tab2spec); // Adding tab1 
+0

我同意,但默認的標籤大小,我們不能改變正確的..它是正確的 – Naruto

+0

它是平衡你有多少標籤。 – andrew