我有个问题。我想有一个文本视图与渐变的颜色。后面还有一个黑色的阴影。问题是阴影使用的是渐变的颜色,而不是调用的颜色(Color.BLACK
)
我的代码是:numberTextView = (TextView)findViewById(R.id.something);
Shader textShaderTop = new LinearGradient(0, 30, 0, 60,
new int[]{Color.parseColor("#A6A6A6"), Color.parseColor("#E8E8E8"), Color.parseColor("#A6A6A6")},
new float[]{0, 0.5f, 1}, TileMode.CLAMP);
numberTextView.getPaint().setShader(textShaderTop);
numberTextView.setShadowLayer(
0.1f, //float radius
20f, //float dx
20f, //float dy
Color.BLACK //this is not black on the screen, but it uses the gradient color!?
);
有人知道该怎么做吗?
发布于 2011-09-21 16:34:20
我也有同样的问题。我设法通过扩展TextView和覆盖onDraw方法来修复它。下面是它看起来的样子
@Override
protected void onDraw(Canvas canvas) {
// draw the shadow
getPaint().setShadowLayer(1, 1, 1, 0xbf000000); // or whatever shadow you use
getPaint().setShader(null);
super.onDraw(canvas);
// draw the gradient filled text
getPaint().clearShadowLayer();
getPaint().setShader(new LinearGradient(0, getHeight(), 0, 0, 0xffacacac, 0xffffffff, TileMode.CLAMP)); // or whatever gradient/shader you use
super.onDraw(canvas);
}
但是,如果您想在渐变中使用具有透明度的颜色,则此方法可能不起作用。
https://stackoverflow.com/questions/7330941
复制相似问题