Putting a break in to a tabs text

穿精又带淫゛_ 提交于 2019-12-24 16:48:46

问题


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.com/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.


回答1:


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.



来源:https://stackoverflow.com/questions/4352879/putting-a-break-in-to-a-tabs-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!