在选项卡文本中添加中断
因此,我正在开发一个使用选项卡界面来更改活动的 UI。我一直在尝试修改此处找到的代码: http://developer. android.com/resources/tutorials/views/hello-tabwidget.html 这样它就能满足我的需求。
但我现在遇到的问题是选项卡所需的文本大小比选项卡本身的宽度长。所以我想知道是否有一种方法可以使其没有图像但有两行文本,或者有两行文本和一个图标。不过,第二个选项是我更喜欢的。
这是我试图修改的代码:
spec = tabHost.newTabSpec("screen").setIndicator("Screen Ratio",
res.getDrawable(R.drawable.ic_tab_artists))
.setContent(intent);
tabHost.addTab(spec);
除了我更改文本的地方之外,代码直接来自教程。这是我尝试编写的第一个应用程序,因此它很大程度上是一项正在进行的工作,但是这些方法中的任何一个都是一个很好的方法,或者是否有更好的方法在一起。任何建议将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想我已经知道如何解决你的换行问题了。
首先:您可以使用方法
setIndicator(CharSequence label)
仅为选项卡设置文本。我能够以这种方式添加换行符:
看起来,保存指示符文本的 TextView 默认情况下已将其 singleLine 属性设置为 true 。因此,如果将其设置为 false,则可以使用 \n 进行换行。
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:
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.