为什么Android会截断我的ActionBar标题? [英] Why Android is truncating my ActionBar title?

查看:74
本文介绍了为什么Android会截断我的ActionBar标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我从显示的每个片段中更改ActionBar中的标题.当我第一次启动我的应用程序时,我得到了一个请求列表,所以标题是我的请求(20)".

In my app, I change the title in the ActionBar from each fragment displayed. When I first start my apps, I got a list of requests, so my title is "My requests (20)".

然后,当您单击该列表中的某个项目时,它将替换活动"中的一个片段,并将标题设置为操作".

Then, when you click on an item in that list, it is replacing a fragment in my Activity and it set the title to "Action".

当我回到第一个视图(总是在同一活动中)时,我将标题重置为我的请求(20)",但是android决定将其截断.结果就是我的要求...".

When I come back to the first view (always in the same Activity), I reset the title to "My requests (20)", but android decide to truncate it. So the result is "My request...".

经过大量测试,当我在其中输入较小的文字时,Android似乎在缩小我的标题.但是,即使有足够的空间,当我放置较长的文本时,它也不会放大.

After much tests, it looks like that Android is shrinking my title when I put a smaller text in it. But it doesn't enlarge it when I put a longer text, even if there is plenty of room.

我该怎么做才能解决这个问题?与在短标题的末尾添加空格相比,我希望有一个更好的解决方案:)

What can I do to solve this? I would like a better solution than adding spaces at the end of my short titles :)

这是我用来更改ActionBar标题的代码:

Here is the code I use to change the title of the ActionBar :

getActivity().getActionBar().setTitle(title);   

推荐答案

我使用自定义标题(如

I solved this problem using a custom title as described in this post.

这是我用来在标签页更改时更改标题的代码

This is the code I use to change the title when a tab changes

((TextView) actionBar.getCustomView().findViewById(R.id.title)).setText(someTitle); 

请注意,在使用操作栏选项卡时,此解决方案在横向模式下将标题置于选项卡的右侧.

Note that this solution places the title to the right of the tabs in landscape mode when using actionbar tabs.

这篇关于为什么Android会截断我的ActionBar标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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