Can Not Find Canvas Variables In Api Level 28
Solution 1:
Those flags have been removed in API 28. See here:
Class android.graphics.Canvas
Removed Methods int save(int)
Removed Fields int CLIP_SAVE_FLAG int CLIP_TO_LAYER_SAVE_FLAG int FULL_COLOR_LAYER_SAVE_FLAG int HAS_ALPHA_LAYER_SAVE_FLAG int MATRIX_SAVE_FLAG
That method was deprecated in API 26. See here:
This method was deprecated in API level 26. Use saveLayer(float, float, float, float, Paint) instead.
What to use instead
According to the Canvas
source code for API 28, the flags you use all combine to be equal to the value of ALL_SAVE_FLAG
:
publicstaticfinalint ALL_SAVE_FLAG = 0x1F;
publicstaticfinalint MATRIX_SAVE_FLAG = 0x01;
publicstaticfinalint CLIP_SAVE_FLAG = 0x02;
publicstaticfinalint HAS_ALPHA_LAYER_SAVE_FLAG = 0x04;
publicstaticfinalint FULL_COLOR_LAYER_SAVE_FLAG = 0x08;
publicstaticfinalint CLIP_TO_LAYER_SAVE_FLAG = 0x10;
From the same source code the call to Canvas#saveLayer(left, top, right, bottom, paint)
defaults to using ALL_SAVE_FLAG
:
/**
* Convenience for {@link #saveLayer(RectF, Paint)} that takes the four float coordinates of the
* bounds rectangle. */
public int saveLayer(floatleft, floattop, floatright, floatbottom, @Nullable Paint paint) {
return saveLayer(left, top, right, bottom, paint, ALL_SAVE_FLAG);
}
So, it looks like your code is equivalent to the following code which you can use as a replacement:
canvas.saveLayer(0, 0, getWidth(), getHeight(), null);
This version of saveLayer() is only available on API 21+. To support lower API levels, use
canvas.saveLayer(0, 0, getWidth(), getHeight(), null, Canvas.ALL_SAVE_FLAG);
Where Canvas.ALL_SAVE_FLAG
is the same as the or'ed values above.
Solution 2:
you can use canvas.save();
instead of canvas.save(Canvas.MATRIX_SAVE_FLAG|CLIP_SAVE_FLAG)
reference
Post a Comment for "Can Not Find Canvas Variables In Api Level 28"