2012-05-02 103 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