如何删除应用于 textpaint 的纹理并应用十六进制颜色?
How to remove texture applied to textpaint and apply hex color?
我使用以下代码将纹理效果应用到我的 textpaint
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),textureRid);
Shader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
textPaint.setShader(shader);
并且这种纹理效果效果很好。但是当我尝试将普通的十六进制颜色应用于 textpaint 时,没有任何变化并且纹理效果仍然存在。当没有应用纹理效果时,下面的代码工作正常。
textPaint.setColor(color);
现在我的理解是,我们需要删除我们应用的着色器或使它无效。所以我尝试将空值传递给setshader,但没有成功。
因此,经过大量研究,即使在使用以下代码应用纹理后,我也能够将正常颜色应用于 textpaint。
Shader textShader=new LinearGradient(0, 0, 0, 25, new int[]{color,color}, new float[]{0, 1}, Shader.TileMode.CLAMP);
textPaint.setShader(textShader);
但我不确定,在我们将shader设置为textpaint之后,将textcolor应用于textpaint才是正确的方法,或者有更好的方法来做。而且当我在应用纹理效果后尝试应用阴影时,我也无法更改 textpaint 的阴影颜色。阴影颜色与文本颜色相同。
textPaint.clearShadowLayer();
textPaint.setShadowLayer(shadowvalue , shadowvalue, shadowvalue, color);
如果有人可以提供您的专业知识,那将非常有帮助。提前致谢。
在使用 setShader 将普通的十六进制颜色应用到之前应用纹理效果的 textpaint 之前,我们必须将 null 作为 @L 传递给 Paint#setShader。在评论中建议使用 Swifter。
textPaint.setShader(null);
编码愉快!
要清除应用的油漆属性,只需使用
textView.paint.reset()
我使用以下代码将纹理效果应用到我的 textpaint
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),textureRid);
Shader shader = new BitmapShader(bitmap, Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
textPaint.setShader(shader);
并且这种纹理效果效果很好。但是当我尝试将普通的十六进制颜色应用于 textpaint 时,没有任何变化并且纹理效果仍然存在。当没有应用纹理效果时,下面的代码工作正常。
textPaint.setColor(color);
现在我的理解是,我们需要删除我们应用的着色器或使它无效。所以我尝试将空值传递给setshader,但没有成功。
因此,经过大量研究,即使在使用以下代码应用纹理后,我也能够将正常颜色应用于 textpaint。
Shader textShader=new LinearGradient(0, 0, 0, 25, new int[]{color,color}, new float[]{0, 1}, Shader.TileMode.CLAMP);
textPaint.setShader(textShader);
但我不确定,在我们将shader设置为textpaint之后,将textcolor应用于textpaint才是正确的方法,或者有更好的方法来做。而且当我在应用纹理效果后尝试应用阴影时,我也无法更改 textpaint 的阴影颜色。阴影颜色与文本颜色相同。
textPaint.clearShadowLayer();
textPaint.setShadowLayer(shadowvalue , shadowvalue, shadowvalue, color);
如果有人可以提供您的专业知识,那将非常有帮助。提前致谢。
在使用 setShader 将普通的十六进制颜色应用到之前应用纹理效果的 textpaint 之前,我们必须将 null 作为 @L 传递给 Paint#setShader。在评论中建议使用 Swifter。
textPaint.setShader(null);
编码愉快!
要清除应用的油漆属性,只需使用
textView.paint.reset()