Android Get Screen dimensions from Service

后端 未结 4 2053
Happy的楠姐
Happy的楠姐 2021-02-02 08:35

I got the Screen Size by using the following from a activity,

Display display = getWindowManager().getDefaultDisplay();

But the same thing is n

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 08:43

    Try this:

    WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
    
    DisplayMetrics displayMetrics = new DisplayMetrics();
    
    wm.getDefaultDisplay().getMetrics(displayMetrics);
    
    int height = displayMetrics.heightPixels;
    int width = displayMetrics.widthPixels;
    

提交回复
热议问题