Home > front end >  display.getRealMetrics() is deprecated
display.getRealMetrics() is deprecated

Time:11-18

I was using getRealMetrics() method and came to know that it is deprecated

val display = this.display
display?.getRealMetrics(outMetrics)

anybody know what is the alternative.

CodePudding user response:

https://developer.android.com/reference/android/view/Display

getRealMetrics(DisplayMetrics outMetrics)

This method was deprecated in API level 31. Use WindowManager#getCurrentWindowMetrics() to identify the current size of the activity window. UI-related work, such as choosing UI layouts, should rely upon WindowMetrics#getBounds(). Use Configuration#densityDpi to get the current density.

CodePudding user response:

try this

Resources.getSystem().displayMetrics

For width and height

Resources.getSystem().displayMetrics.widthPixels
Resources.getSystem().displayMetrics.heightPixels
  • Related