如果Android ActionBar的标题太长,是否有可能使其自动滚动(跑马灯)?
如果Android ActionBar的标题太长,是否有可能使其自动滚动(跑马灯)?
我是这样做的:
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) {
}