2011-05-25 83 views
0

我只想在我的TabLayout的选项卡中使用文本。不幸的是,默认情况下,制表符非常大,文本非常小。我没有办法调整文本的大小或标签的高度,没有使用TabSpec.setIndicator(View);这将是非常不可取的,因为那时我会定义一个特定的布局,选择器,选定的图像,未选中的图像等等,所以我的选项卡不适合每个设备的外观和感觉。有没有一种方便的方式来定制Tab外观?Android:漂亮的TabLayout?

mTabHost.addTab(mTabHost.newTabSpec("system").setIndicator("My first tab").setContent(R.id.fileBrowserTabHostSystemList)); 
mTabHost.addTab(mTabHost.newTabSpec("recent").setIndicator("My Second tab").setContent(R.id.fileBrowserTabHostRecentList)); 

enter image description here

+3

这是我遇到的最好的例子:http://joshclemm.com/blog/?p=136 – Smith3 2011-05-25 14:58:46

+0

我真的不喜欢这样做,因为我想我的选项卡使用本地外观和感觉。 – ab11 2011-05-25 17:42:48

回答

2

我已成功地改变一种很好的方式的标签高度:

final int tabChildrenCount = tabWidget.getChildCount(); 
    View currentTab; 
    for (int i = 0; i < tabChildrenCount; i++) { 
     currentTab= tabWidget.getChildAt(i); 
     currentTab.getLayoutParams().height = 32; 
    } 
    tabWidget.getLayoutParams().height = LayoutParams.WRAP_CONTENT; 
    tabWidget.requestLayout(); 

Tabs with smaller height

我也试图拿到冠军的高度,在该选项卡并设置标签的高度:

currentTab.findViewById(android.R.id.title).getHeight(); 
// also tried with getMeasuredHeight() 

但它返回0,因为它在onCreate()方法中,并且视图似乎不知道它的大小。 LayoutParams.WRAP_CONTENT对于选项卡高度并不好,因为它充当FILL_PARENT。

但是,请注意,此解决方案只假定标签的标题将适合32像素。

仍然最安全的猜测是手动执行布局(因为已发布http://joshclemm.com/blog/?p=136)。从Android存储库获取资源并进行定制:)

+0

我想没有好的方法去做这件事。感谢您的建议。 – ab11 2011-05-25 17:42:12

+0

ab11,检查新的解决方案。 – Kamen 2011-05-26 09:04:29

+0

Kamen,谢谢,这很有帮助。 – ab11 2011-05-26 12:30:40