5

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

Toni4780
  • 443
  • 1
  • 8
  • 14

2 Answers2

4

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.

Hiren Patel
  • 52,124
  • 21
  • 173
  • 151
3

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

Community
  • 1
  • 1
Sam Dozor
  • 40,335
  • 6
  • 42
  • 42