getting the screen density programmatically in android?

后端 未结 19 2672
感动是毒
感动是毒 2020-11-22 01:56

How to get the screen density programmatically in android?

I mean: How to find the screen dpi of the current device?

19条回答
  •  情话喂你
    2020-11-22 02:41

    If you want to retrieve the density from a Service it works like this:

    WindowManager wm = (WindowManager) this.getSystemService(Context.WINDOW_SERVICE);
    DisplayMetrics metrics = new DisplayMetrics();
    wm.getDefaultDisplay().getMetrics(metrics);
    

提交回复
热议问题