Error getting window size on android: “The method getWindowManager is undefined”

前端 未结 6 2241
半阙折子戏
半阙折子戏 2020-12-18 20:08

I need to get the window height and the weight.
I have this in my code:

DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDispl         


        
6条回答
  •  别那么骄傲
    2020-12-18 20:31

    it works for me

    import android.app.Activity;
    
    ((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
    
    mediaProjectionManager = (MediaProjectionManager)((Activity) getContext()).getSystemService(Context.MEDIA_PROJECTION_SERVICE);
    

提交回复
热议问题