在标签文本中加入中断 [英] Putting a break in to a tabs text

查看:30
本文介绍了在标签文本中加入中断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我正在开发一个使用选项卡界面来更改活动的 UI.我一直在尝试修改此处找到的代码:http://developer.android.com/resources/tutorials/views/hello-tabwidget.html 以便它满足我的需求.

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.

这是我要修改的代码:

        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.

首先:可以使用方法

setIndicator(CharSequence label) 用于仅设置标签文本.

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);

看起来,保存指示器文本的 TextView 已默认将其 singleLine 属性设置为 true.因此,如果将其设置为 false,则可以使用 \n 来换行.

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.

这篇关于在标签文本中加入中断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆