简体   繁体   English

折叠工具栏布局android标题椭圆形

[英]collapsing toolbar layout android title ellipsizes

I'm using android design support library 25.0.1, there is one issue with the title in the collapsing toolbar layout, my title is long and it is ellipsized in expanded condition even when there is space for it to show. 我正在使用android设计支持库25.0.1,在折叠工具栏布局中有一个标题问题,我的标题很长,即使有空间显示,它也会在展开状态下进行椭圆化处理。

Is there any solution by which we can show title with ellipsize off in the expanded mode . 是否有任何解决方案,我们可以在展开模式下使用ellipsize显示标题。 .

although there is some space availbale the title is ellispsized 尽管有一些空间可用,但标题仍然是无效的

collapsing toolbar code : 折叠工具栏代码:

<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">

You can create custom Marquee-able Toolbar, This code may help you 您可以创建自定义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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM