The shadow layer works with the emulator, but not on the device itself

I am creating a custom drawable (it extends from Drawable) and I am trying to apply a shadow effect to it.

Here is part of my code:

public void draw(Canvas canvas) { Path path = new Path(); path.moveTo(0, 0); path.lineTo(0, Y/2); path.lineTo(X/2, Y); path.lineTo(X, Y/2); path.lineTo(X, 0); path.lineTo(0, 0); Paint paint = new Paint(); paint.setColor(context.getResources().getColor(R.color.red_dark)); paint.setStyle(Style.FILL_AND_STROKE); paint.setStrokeWidth(2f); paint.setShadowLayer(1, 0, 10f, context.getResources().getColor(R.color.black)); canvas.drawPath(path, paint); } 

I don’t know why, but it puts a shadow with the same color, I double-checked everything and I don’t see where the problem is. I test it on a galactic connection. But on the emulator, it works fine.

+6
source share
1 answer

I'm not sure, but this is possible due to hardware acceleration. setShadowLayer doen't work if browsing is accelerated. Try disabling acceleration for the entire application and check. Read this.

Unsupported drawing operations

setShadowLayer (): only works with text

Use the type of software layer to force the view to appear in the software. If a view that is hardware accelerated (for example, if your entire application is hardware acclerated) has rendering problems, this is an easy way to get around the limitations of the hardware rendering pipeline.

Use setLayerType to set the layer type to separate views or to disable acceleration in the manifest for the entire application.

+10
source

All Articles