How to get screen display metrics in application class

前端 未结 6 541
自闭症患者
自闭症患者 2020-11-30 10:38

If I put this in some activity class it works perfectly but, when I put it in my App class the method getWindowManager() can not be found. Is there some way to

6条回答
  •  無奈伤痛
    2020-11-30 11:25

    Without Context use -

    Resources.getSystem().displayMetrics.widthPixels
    

    With Context -

    context?.resources?.displayMetrics?.widthPixels
    

    Note : getWindowManager().getDefaultDisplay().getMetrics(dm); returns void in the new API.

提交回复
热议问题