Friday, July 30, 2010

Android Title Marquee

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();

11 comments:

  1. Hi. I tried the code but does not work. Even I set max lines to 1. Are you sure TextView is focusable?

    ReplyDelete
  2. Yew Felix I too didnt find this working..

    ReplyDelete
  3. Thanks, worked straight away as-is. The only edit I needed was to change to setMarqueeRepeatLimit(-1) for continuous scrolling.

    ReplyDelete
  4. Thanks, worked out of the box.

    ReplyDelete
  5. I'm not sure why you think that's "hackish". That's simply a feature of the system. :D

    ReplyDelete
  6. It doesn't work for me either...

    ReplyDelete
  7. Make sure of
    1)title.setMarqueeRepeatLimit(-1); in java file
    2)android:singleLine="true" attribute in TextView of layout.xml file.
    3) in manifest file.

    Works like a charm...Thanks Felix :)

    ReplyDelete
  8. Hi All,

    Thanks a lot for the code, it works like a charm. Anyway I'm currently using the native ActionBar provided by the Theme.Holo theme of android, and I had a hard time finding the title item. So I'll share some code required to ensure you are using the title TextView of the ActionBar.

    From the main activity of your application you can do this: http://pastebin.com/jVtEi3GD

    I hope someone finds this usefull.

    Regards.

    ReplyDelete
    Replies
    1. Wow man you did it, i was fooling around looking for the $·"%$ id, thank you.

      Delete
  9. Your Affiliate Money Printing Machine is ready -

    Plus, getting it set up is as easy as 1--2--3!

    Here's how it all works...

    STEP 1. Input into the system what affiliate products the system will advertise
    STEP 2. Add some PUSH button traffic (this LITERALLY takes 2 minutes)
    STEP 3. See how the system explode your list and upsell your affiliate products on it's own!

    Are you ready to start making money??

    Get the full details here

    ReplyDelete
  10. Compre documentos en línea, documentos originales y registrados.
    Acerca de Permisodeespana, algunos dicen que somos los solucionadores de problemas, mientras que otros se refieren a nosotros como vendedores de soluciones. Contamos con cientos de clientes satisfechos a nivel mundial. Hacemos documentos falsos autorizados y aprobados como Permiso de Residencia Español, DNI, Pasaporte Español y Licencia de Conducir Española. Somos los fabricantes y proveedores de primer nivel de estos documentos, reconocidos a nivel mundial.

    Comprar permiso de residencia,
    permiso de residenciareal y falso en línea,
    Compre licencia de conducir en línea,
    Compre una licencia de conducir española falsa en línea,
    Comprar tarjeta de identificación,
    Licencia de conducir real y falsa,
    Compre pasaporte real en línea,

    Visit Here fpr more information. :- https://permisodeespana.com/licencia-de-conducir-espanola/
    Address: 56 Guild Street, London, EC4A 3WU (UK)
    Email: contact@permisodeespana.com
    WhatsApp: +443455280186

    ReplyDelete