Search code examples
javaandroidpaint

Android - paint.setShadowLayer Ignoring shadowColor


I am facing issue with shadow color, setShadowLayer method is ignoring shadowColor (Here i specified Color.RED in my code) instead of setShadowLayer is taking paint color (Here Color.argb(255, 50, 153, 187)). Below is my paint settings and find attached image for reference, thanksenter 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);

Solution

  • the shadowLayer works only it the hardware acceleration is disabled. Add

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

    and it should work