【问题标题】:How to ellipsize an title of activity on Android如何在Android上省略活动标题
【发布时间】:2012-06-16 06:44:18
【问题描述】:

我正在尝试省略活动的标题,有人可以告诉我怎么做吗?

setTitle("My Title");
//when the text of the title gets too long, how can I use setEllipsize() here? how can I get the view Id of that title?

【问题讨论】:

标签: android android-activity title


【解决方案1】:

试试这个:http://it-ride.blogspot.pt/2010/07/android-title-marquee.html 那里有人说有效,也有人说无效。

【讨论】:

    【解决方案2】:

    代码基于此网页链接 http://it-ride.blogspot.pt/2010/07/android-title-marquee.html

    // make the title scroll!
             // find the title TextView
             TextView title = (TextView) findViewById(android.R.id.title);
             // set the ellipsize mode to MARQUEE and make it scroll only once
    
             title.setEllipsize(TruncateAt.MARQUEE);
             title.setMarqueeRepeatLimit(1);
             // in order to start strolling, it has to be focusable and focused
             title.setFocusable(true);
             title.setFocusableInTouchMode(true);
             title.requestFocus();
    

    【讨论】:

    • 不幸的是,上面的代码对我不起作用,但无论如何感谢您的回复!
    • 您遇到了什么问题,我会竭尽全力解决您的问题。
    • 嗨 Alexander,问题是当文本太长时,我无法在活动标题的文本末尾添加省略号,因此标题中的文本将被截断。跨度>
    • findViewById(android.R.id.title) 并没有真正返回活动标题的视图,所以上面的代码对我不起作用......
    • 没关系,我刚刚解决了!诀窍是我需要 setSingleLine(true) 以省略文本视图。谢谢大家的帮助!!
    猜你喜欢
    • 2015-03-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-27
    • 1970-01-01
    • 1970-01-01
    • 2019-08-01
    • 2017-11-10
    相关资源
    最近更新 更多