So I am working on a UI that use a tab interface to change activities. I have been trying to modify the code found here: http://developer.android.c开发者_如何转开发om/resources/tutorials/views/hello-tabwidget.html so that it will fit my needs.
But the issue I am having right now is that the size of the text required for the tabs is longer then the width of the tab its self. So what I was wondering is if either there is a way to make it so that there is no image but have two lines of text instead or that there is two lines of text and an icon. The second option is the one i prefer though.
Here is the code I am trying to modify:
spec = tabHost.newTabSpec("screen").setIndicator("Screen Ratio",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
The code is straight out of the tutorial except for where I changed the text. This is the first app I have tried to write so it is very much a work in progress but are either of these methods even a good way to go about it or is there a better way all together. Any suggestions would be great appreciated.
I think I figured out how to solve your problem with the line breaks.
First of all: You can use the method
setIndicator(CharSequence label)
for setting only text to your tab.
I was able to add line breaks in this way:
TextView title = (TextView) mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title);
title.setSingleLine(false);
It seems, that the TextView holding the indicator text, has set its singleLine attribute to true by default. So if you set it to false you can use \n for line breaks.
精彩评论