使用textShadow折叠工具栏

时间:2015-06-17 13:32:20

标签: android android-collapsingtoolbarlayout

我有折叠工具栏的问题,在展开状态下我希望文本下面有模糊阴影,我使用此代码:

child_process.spawn('mspec.exe', options.args, {cwd: '...'});

with:

collapsingToolbar.setExpandedTitleTextAppearance(R.style.toolbar_text);

我可以更改<style name="toolbar_text"> <item name="android:textColor">@color/white</item> <item name="android:shadowColor">@color/black</item> <item name="android:shadowDx">2</item> <item name="android:shadowDy">2</item> <item name="android:shadowRadius">4</item> </style> ,它可以正常工作,但影子不起作用。我为阴影尝试了很多不同的值。

是否可以为折叠文本投射阴影?因为在浅色图像上,标题有时难以阅读。

3 个答案:

答案 0 :(得分:5)

请使用文字保护网格,而不是使用文字阴影。请参阅此问题:Android CollapsingToolbarLayout Title background

答案 1 :(得分:1)

从设计支持lib版本22.2.1看起来,它是不可能的。

这是用于设置文本外观的解编译方法:

void setExpandedTextAppearance(int resId) {
    TypedArray a = this.mView.getContext().obtainStyledAttributes(resId, styleable.TextAppearance);
    if(a.hasValue(styleable.TextAppearance_android_textColor)) {
        this.mExpandedTextColor = a.getColor(styleable.TextAppearance_android_textColor, 0);
    }

    if(a.hasValue(styleable.TextAppearance_android_textSize)) {
        this.mExpandedTextSize = (float)a.getDimensionPixelSize(styleable.TextAppearance_android_textSize, 0);
    }

    a.recycle();
    this.recalculate();
}

它只设置文字颜色和大小。

更新:由于您提到需要在标题上添加阴影以便于在浅色背景上阅读,我建议您将扩展的标题颜色更改为深色。 E.g。

collapsingToolbar.setExpandedTitleColor(0x000);

答案 2 :(得分:0)

我通过以下代码获得了Acheived文字阴影。我在ImageView的位置使用了FrameLayout,而FrameLayout同时具有ImageView和带背景渐变的View。

  •         <ImageView
                android:id="@+id/groupIcon"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                android:src="@drawable/drawer_header_background"
                app:layout_collapseMode="parallax" />
    
            <View
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/coll_toolbar_image_gradient" />
        </FrameLayout>
    

coll_toolbar_image_gradient.xml

<gradient
    android:angle="90"
    android:centerColor="#00ffffff"
    android:endColor="#aa000000"
    android:startColor="#aa000000" />
<corners android:radius="0dp" />

相关问题