Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Autoscrollable title in Android Actionbar (Marquee)

is there a possibility to make the title of an Android ActionBar scroll automatically (marquee) if it's too large?

like image 527
Toni4780 Avatar asked Apr 05 '12 19:04

Toni4780


2 Answers

Well I have done this way:

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

    try {
        Field f = toolbar.getClass().getDeclaredField("mTitleTextView");
        f.setAccessible(true);
        TextView toolbarTextView = (TextView) f.get(toolbar);
        toolbarTextView.setEllipsize(TextUtils.TruncateAt.MARQUEE);
        toolbarTextView.setFocusable(true);
        toolbarTextView.setFocusableInTouchMode(true);
        toolbarTextView.requestFocus();
        toolbarTextView.setSingleLine(true);
        toolbarTextView.setSelected(true);
        toolbarTextView.setMarqueeRepeatLimit(-1);

        // set text on Textview

        toolbarTextView.setText("Hello Android ! This is a sample marquee text. That's great. Enjoy");
    } catch (NoSuchFieldException e) {
    } catch (IllegalAccessException e) {
    }

Hope this will help you.

like image 104
Hiren Patel Avatar answered Sep 19 '22 16:09

Hiren Patel


You could try implementing my answer to this question and add android:ellipsize="marquee" to the TextView...? Worth a shot.

like image 32
Sam Dozor Avatar answered Sep 21 '22 16:09

Sam Dozor