Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 使用textShadow折叠工具栏_Android_Android Collapsingtoolbarlayout - Fatal编程技术网

Android 使用textShadow折叠工具栏

Android 使用textShadow折叠工具栏,android,android-collapsingtoolbarlayout,Android,Android Collapsingtoolbarlayout,我在折叠工具栏时遇到问题,在展开状态下,我希望文本下方有模糊阴影,我使用以下代码: collapsingToolbar.setExpandedTitleTextAppearance(R.style.toolbar_text); 与: <style name="toolbar_text"> <item name="android:textColor">@color/white</item> <item name="android:shad

我在折叠工具栏时遇到问题,在展开状态下,我希望文本下方有模糊阴影,我使用以下代码:

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>

@颜色/白色
@颜色/黑色
2.
2.
4.
我可以更改
textColor
,它可以工作,但阴影不工作。我尝试了很多不同的阴影值


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

看起来,从设计支持库版本
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();
}
它只设置文本的颜色和大小

更新:由于您提到需要在标题中添加阴影,以便于在浅色背景下阅读,因此我建议您将扩展的标题颜色更改为深色。例如

collapsingToolbar.setExpandedTitleColor(0x000);

不要使用textshadow,而是使用文本保护scrim。查看此问题:

我已通过以下代码获得文本阴影。我在ImageView位置使用了FrameLayout,FrameLayout同时具有ImageView和背景渐变视图

  • 
    
coll_toolbar_image_gradient.xml



您解决了这个问题吗?没有,它与Google appcompat库有关。也许等更新吧,现在已经修好了。
        <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>
<gradient
    android:angle="90"
    android:centerColor="#00ffffff"
    android:endColor="#aa000000"
    android:startColor="#aa000000" />
<corners android:radius="0dp" />