Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.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 在文本中设置渐变_Android_Textview_Gradient - Fatal编程技术网

Android 在文本中设置渐变

Android 在文本中设置渐变,android,textview,gradient,Android,Textview,Gradient,我想要这个输出: 这两种颜色是: <color name="clrc2">#c27a1c</color> <color name="clrfe">#fee17f</color> 我没有达到预期的结果 这是我得到的结果: 通过此代码获得准确的梯度: Shader shader = new LinearGradient(0,100,10,100, new int[]{resources.getColor(R.

我想要这个输出:

这两种颜色是:

<color name="clrc2">#c27a1c</color>
    <color name="clrfe">#fee17f</color>
我没有达到预期的结果

这是我得到的结果:


通过此代码获得准确的梯度:

Shader shader = new LinearGradient(0,100,10,100,
                new int[]{resources.getColor(R.color.clrc2),resources.getColor(R.color.clrfe),resources.getColor(R.color.clrc2)}
                ,new float[]{0.4f,0.2f,0.4f}, Shader.TileMode.MIRROR);
        option_.setTextColor(resources.getColor(R.color.clrc2));
        option_.getPaint().setShader( shader );
Shader textShader = new LinearGradient(0, 8, 0, 18,
            new int[]{Color.parseColor("#c27a1c"), Color.parseColor("#fee17f")},
            new float[]{0, 1}, Shader.TileMode.MIRROR);
    option_.setTextColor(resources.getColor(R.color.clrfe));
    option_.getPaint().setShader(textShader);

Ref from:

添加您的结果图像,以便可以建议答案或编辑…@androidnoobdev添加了结果image@androidnoobdev运气好吗?