Android 使用省略号字幕折叠工具栏布局标题

Android 使用省略号字幕折叠工具栏布局标题,android,material-design,Android,Material Design,我想使用android的CollasingToolbarLayout,但是有一个标题,如果布局被折叠,它将水平滚动而不是被截断。 我尝试使用以下样式调用setcollapsedtitletextearance,但这对字幕没有任何影响(只有文本颜色和大小) 20便士 大胆的 @颜色/材质\u蓝色\u 600 帐篷 1. 真的 真的 永远的帐篷 我错过什么了吗?实现这种行为的最佳方式是什么?谢谢。我自己在试图省去一个折叠工具栏布局时遇到了类似的问题。在对android SDK中处理TitleTe

我想使用android的
CollasingToolbarLayout
,但是有一个标题,如果布局被折叠,它将水平滚动而不是被截断。 我尝试使用以下样式调用
setcollapsedtitletextearance
,但这对字幕没有任何影响(只有文本颜色和大小)


20便士
大胆的
@颜色/材质\u蓝色\u 600
帐篷
1.
真的
真的
永远的帐篷

我错过什么了吗?实现这种行为的最佳方式是什么?谢谢。

我自己在试图省去一个
折叠工具栏布局时遇到了类似的问题。在对android SDK中处理
TitleTextAppearance
的位置进行调查后,似乎只有少数文本外观指令得到遵守:

textColor
textSize
shadowColor
shadowDy
shadowDx
shadowRadius
字体

collasingtorbalayout
类使用
collasingtexthelper
应用文本外观,请参见下面的相关方法:

void setCollapsedTextAppearance(int resId) {
    TintTypedArray a = TintTypedArray.obtainStyledAttributes(mView.getContext(), resId,
            android.support.v7.appcompat.R.styleable.TextAppearance);
    if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor)) {
        mCollapsedTextColor = a.getColorStateList(
                android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor);
    }
    if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize)) {
        mCollapsedTextSize = a.getDimensionPixelSize(
                android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize,
                (int) mCollapsedTextSize);
    }
    mCollapsedShadowColor = a.getInt(
            android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowColor, 0);
    mCollapsedShadowDx = a.getFloat(
            android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDx, 0);
    mCollapsedShadowDy = a.getFloat(
            android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDy, 0);
    mCollapsedShadowRadius = a.getFloat(
            android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();
    if (Build.VERSION.SDK_INT >= 16) {
        mCollapsedTypeface = readFontFamilyTypeface(resId);
    }
    recalculate();
}
正如Lovis所说,如果你想让ellipsize指令得到尊重,你必须实现你自己的
CollasingToolbarLayout
CollasingTextHelper


collasingtexthelper
类的完整源代码:

我不确定,但是只有当
TextView
聚焦时,afaik字幕才起作用。由于工具栏中的
TextView
永远不会被聚焦,因此您必须创建一些自定义解决方案
void setCollapsedTextAppearance(int resId) {
    TintTypedArray a = TintTypedArray.obtainStyledAttributes(mView.getContext(), resId,
            android.support.v7.appcompat.R.styleable.TextAppearance);
    if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor)) {
        mCollapsedTextColor = a.getColorStateList(
                android.support.v7.appcompat.R.styleable.TextAppearance_android_textColor);
    }
    if (a.hasValue(android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize)) {
        mCollapsedTextSize = a.getDimensionPixelSize(
                android.support.v7.appcompat.R.styleable.TextAppearance_android_textSize,
                (int) mCollapsedTextSize);
    }
    mCollapsedShadowColor = a.getInt(
            android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowColor, 0);
    mCollapsedShadowDx = a.getFloat(
            android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDx, 0);
    mCollapsedShadowDy = a.getFloat(
            android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowDy, 0);
    mCollapsedShadowRadius = a.getFloat(
            android.support.v7.appcompat.R.styleable.TextAppearance_android_shadowRadius, 0);
    a.recycle();
    if (Build.VERSION.SDK_INT >= 16) {
        mCollapsedTypeface = readFontFamilyTypeface(resId);
    }
    recalculate();
}