【发布时间】:2012-04-05 19:16:42
【问题描述】:
如果 Android ActionBar 的标题太大,是否有可能使标题自动滚动(选框)?
【问题讨论】:
标签: android android-widget android-actionbar android-scroll
如果 Android ActionBar 的标题太大,是否有可能使标题自动滚动(选框)?
【问题讨论】:
标签: android android-widget android-actionbar android-scroll
好吧,我已经这样做了:
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) {
}
希望这会对你有所帮助。
【讨论】:
您可以尝试实现我对this question 的回答并将android:ellipsize="marquee" 添加到TextView...?值得一试。
【讨论】: