开发者

Is there a workaround to the loss of the state drawables when passing a TextView to the setIndicator method of a TabSpec?

I am implementing a Tabbed Layout in an application where vertical screen real estate is of the utmost importance, and so I have resized the height of the tabs in the XML layout. The tabs do not have an icon drawable resource, they have basic text labels. I am using the setIndicator(CharSequence) method when setting the TabSpec programatically, but it would seem that even when using this method the Android OS reserves the top of the tab for an icon and it also seems to resize the tabs from the bottom up. As a result my tabs are so short that the text label on the tab is not visible.

From what I've gathered through my Googling and also from other Stack Overflow questions, the best way to address this issue is to use a TextView instead of a CharSequence for the Indicator. So, I have tried programatically declaring a new TextView, and then passing it in to the setIndicator method. The text label is now visible, but, the tab has absolutely no visual styling/state drawables what so ever. Further, if that tab is active, the text itself is no longer visible due to the lack of state drawables. This is obviously also a problem.

I would like to post the code I am using, but the nature of the project prevents me from sharing an开发者_Python百科y source. I can however say the following:

  • In programatically creating the TextView, I have tried doing as little work as simply setting the text, through to as much as using the LayoutParams(int, int) and setBackgroundColor and many other properties. I have tried using completely transparent values for the backgroundColor. No avail.
  • I have not tried creating the TextView as an XML resource and bringing using it in that fashion, though I don't see how that would change the outcome.

And so my question is the following:

Is there any way to achieve short tabs that have only a text label without having to go through the process of extending classes or creating sets of state drawable resources? While these are mostly simple tasks, the nature of this app is that it is on an extremely short turn-around time and presentation/user chrome is of the utmost non-importance; currently functionality is priority number one and if I can save time by using the provided UI elements then that is the route I would prefer to take since I don't really have the ability to download a bunch of graphic editing software on my workstation without headaches and I'm also the only one working on the project, further, the only one here who is permitted to work on the project. My apologies for the nebulousness of this whole affair.

Thanks in advance.


I refer you to my answer in this question.

I use this code to set the indicator

TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;

intent = new Intent().setClass(this, activity1.class);
spec = tabHost.newTabSpec("tab1").setIndicator("tab1").setContent(intent);
tabHost.addTab(spec);

intent = new Intent().setClass(this, activity2.class);
spec = tabHost.newTabSpec("tab2").setIndicator("tab2").setContent(intent);
tabHost.addTab(spec);
...
// set height of tabs
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = 30; // where child 0 refers "tab1"
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = 30; // where child 1 refers "tab2"

Hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜