I recently wanted the title of my activity to scroll like a marquee whenever it was too long to fit in its space (because it is fetched from the net and can be pretty much anything). I didn't want to use a custom multi-line title view because that would waste screen space and because I want to preserve the native look and feel. The solution I've found is rather hackish, but it works. Here goes the code, with explanatory comments and all:
// 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();
Hi. I tried the code but does not work. Even I set max lines to 1. Are you sure TextView is focusable?
ReplyDeleteYew Felix I too didnt find this working..
ReplyDeleteThanks, worked straight away as-is. The only edit I needed was to change to setMarqueeRepeatLimit(-1) for continuous scrolling.
ReplyDeleteThanks, worked out of the box.
ReplyDeleteI'm not sure why you think that's "hackish". That's simply a feature of the system. :D
ReplyDeleteIt doesn't work for me either...
ReplyDelete