[英]collapsing toolbar layout android title ellipsizes
我正在使用android设计支持库25.0.1,在折叠工具栏布局中有一个标题问题,我的标题很长,即使有空间显示,它也会在展开状态下进行椭圆化处理。
是否有任何解决方案,我们可以在展开模式下使用ellipsize显示标题。 。
折叠工具栏代码:
<net.opacapp.multilinecollapsingtoolbar.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="@color/white"
app:titleEnabled="true"
app:expandedTitleGravity="center_horizontal"
app:expandedTitleMarginTop="75dp"
app:expandedTitleTextAppearance="@style/ExpandedAppBar"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
您可以创建自定义Marquee-able工具栏,此代码可以帮助您
public class MarqueeToolbar extends Toolbar {
TextView title;
public MarqueeToolbar(Context context) {
super(context);
}
public MarqueeToolbar(Context context, AttributeSet attrs) {
super(context, attrs);
}
public MarqueeToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
@Override
public void setTitle(CharSequence title) {
if (!reflected) {
reflected = reflectTitle();
}
super.setTitle(title);
selectTitle();
}
@Override
public void setTitle(int resId) {
if (!reflected) {
reflected = reflectTitle();
}
super.setTitle(resId);
selectTitle();
}
boolean reflected = false;
private boolean reflectTitle() {
try {
Field field = Toolbar.class.getDeclaredField("mTitleTextView");
field.setAccessible(true);
title = (TextView) field.get(this);
title.setEllipsize(TextUtils.TruncateAt.MARQUEE);
title.setMarqueeRepeatLimit(-1);
return true;
} catch (NoSuchFieldException e) {
e.printStackTrace();
return false;
} catch (IllegalAccessException e) {
e.printStackTrace();
return false;
} catch (NullPointerException e) {
e.printStackTrace();
return false;
}
}
public void selectTitle() {
if (title != null)
title.setSelected(true);
}
}
我正在使用https://github.com/opacapp/multiline-collapsingtoolbar这个库来解决我的问题,除了标题中的阴影外,它的效果很好
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.