I only want to use text in the tabs of my TabLayout. Unfortunately, by default, the Tabs are very large and the text is very small. I see no way of adjusting the size of the text or height of the tabs, without using TabSpec.setIndicator(View)
; which would be very undesirable because then I would have define a specific layout, selector, selected image, unselected image, etc... so my tabs would not fit the look and feel of each device. Is there a convenient way to customize the Tab appearance?
mTabHost.addTab(mTabHost.newTabSpec("system").setIndicator("My first tab").setContent(R.id.f开发者_运维问答ileBrowserTabHostSystemList));
mTabHost.addTab(mTabHost.newTabSpec("recent").setIndicator("My Second tab").setContent(R.id.fileBrowserTabHostRecentList));
I have managed to change the tab height in a nice way:
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();
I also tried to get the height of the title in the tab and to set tab's height to it:
currentTab.findViewById(android.R.id.title).getHeight();
// also tried with getMeasuredHeight()
but it returns 0 since it was in the onCreate() method and the view seems to not know its size at that moment. LayoutParams.WRAP_CONTENT is no good for the tab height, because it acted as FILL_PARENT.
Note, however, that this solution only assumes that the title of the tab will fit in 32 pixels.
Still the safest guess is to manually do the layout (as already posted http://joshclemm.com/blog/?p=136). Get the resources from Android Repository and customtize :)
精彩评论