Marquee title in Toolbar / ActionBar in Android with Lollipop SDK?

后端 未结 5 1638
清歌不尽
清歌不尽 2021-01-04 19:38

I\'ve tried several different approaches, including the one found here (which in turn led me to trying both of the top answers to this question), as well as using reflection

5条回答
  •  [愿得一人]
    2021-01-04 20:22

    Get the title TextView object from declared field name of TextView in Toolbar class and Marquee title of toolbar.

        TextView titleTextView = null;
    
        try {
            Field f = toolbar.getClass().getDeclaredField("mTitleTextView");
            f.setAccessible(true);
            titleTextView = (TextView) f.get(toolbar);
    
            titleTextView.setEllipsize(TruncateAt.MARQUEE);
            titleTextView.setFocusable(true);
            titleTextView.setFocusableInTouchMode(true);
            titleTextView.requestFocus();
            titleTextView.setSingleLine(true);
            titleTextView.setSelected(true);
            titleTextView.setMarqueeRepeatLimit(-1);
    
        } catch (NoSuchFieldException e) {
        } catch (IllegalAccessException e) {
        }
    

提交回复
热议问题