I am drawing image on canvas which in turn in fullscreen, it is drawn behind navigation and status bars.
@Override
public void onDraw(Canvas canvas) {
super.onDraw(canvas);
Bitmap b = BitmapFactory.decodeResource(getResources(), R.drawable.background_try9);
bgTrans = Bitmap.createScaledBitmap(b, canvas.getWidth(), canvas.getHeight(), false);
canvas.drawBitmap(bgTrans, 0, 0, paint);
}
Now I want to move this outside onDraw
method.
I know I can use DisplayMetrics
like this
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
int width = displayMetrics.widthPixels;
int height = displayMetrics.heightPixels;
But I have read that sometimes it can report wrong/null value. Also after checking it out, it seem heightPixels does not count navigation bar height. Is there way to get canvas sizes before entering onDraw
?