2

I'm trying to ellipsize the title of an activity, could anyone please let me know how to do it?

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?
FoamyGuy
  • 46,603
  • 18
  • 125
  • 156
Green Ho
  • 881
  • 3
  • 14
  • 27
  • So maybe check it: http://stackoverflow.com/questions/10779037/set-activity-title-ellipse-to-middle – pawegio Jun 15 '12 at 22:10

2 Answers2

0

Try this: http://it-ride.blogspot.pt/2010/07/android-title-marquee.html Some of the people there say it works, some others say it doesn't.

Nuno Gonçalves
  • 6,202
  • 7
  • 46
  • 66
-1

The code is based on this web link 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();

enter image description here

al23dev
  • 845
  • 2
  • 8
  • 17
  • Unfortunately the code above doesn't work for me, but thanks anyway for the response! – Green Ho Jun 16 '12 at 01:01
  • what is the problem you are having and I will en devour to fix your problem. – al23dev Jun 16 '12 at 11:13
  • Hi Alexander, the problem is I can't add ellipsis to the end of the text of the activity title when the text gets too long, so the text in the title will just be truncated. – Green Ho Jun 18 '12 at 16:29
  • findViewById(android.R.id.title) doesn't really return the view of the activity's title, so the code above doesn't work for me... – Green Ho Jun 18 '12 at 16:31
  • never mind, I just worked it out!! The trick is I need to setSingleLine(true) in order to ellipsize the text view. Thanks everyone for all the help!! – Green Ho Jun 18 '12 at 17:07