Android - paint.setShadowLayer忽略shadowColor

时间:2015-01-13 15:52:55

标签: java android paint

我面临着阴影颜色的问题,setShadowLayer方法忽略了shadowColor(这里我在我的代码中指定了Color.RED)而不是setShadowLayer正在采用颜色(这里是Color.argb(255,50,153,187))。下面是我的绘画设置并找到附件图片以供参考,感谢enter image description here

    paint.setAntiAlias(true);
    paint.setColor(Color.argb(255, 50, 153, 187));
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeJoin(Paint.Join.ROUND);
    paint.setStrokeWidth(STROKE_WIDTH);
    paint.setStrokeCap(Paint.Cap.ROUND);
    paint.setShadowLayer(7.0f, 20.0f, 2.0f, Color.RED);

1 个答案:

答案 0 :(得分:11)

shadowLayer仅在禁用硬件加速时起作用。添加

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { 
      setLayerType(LAYER_TYPE_SOFTWARE, paint); 
}

它应该有效