Android获取虚拟软键盘高度

 1 public static int getDpi(Context context) {
 2         int dpi = 0;
 3         WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
 4         Display display = windowManager.getDefaultDisplay();
 5         DisplayMetrics displayMetrics = new DisplayMetrics();
 6         @SuppressWarnings("rawtypes")
 7         Class c;
 8         try {
 9             c = Class.forName("android.view.Display");
10             @SuppressWarnings("unchecked")
11             Method method = c.getMethod("getRealMetrics", DisplayMetrics.class);
12             method.invoke(display, displayMetrics);
13             dpi = displayMetrics.heightPixels;
14         } catch (Exception e) {
15             e.printStackTrace();
16         }
17         return dpi;
18     }
1 public static int getScreenHeight(Context context) {
2         WindowManager wm = (WindowManager) context
3                 .getSystemService(Context.WINDOW_SERVICE);
4         DisplayMetrics outMetrics = new DisplayMetrics();
5         wm.getDefaultDisplay().getMetrics(outMetrics);
6         return outMetrics.heightPixels;
7     }
 1 /**
 2      * 获取 虚拟按键的高度
 3      *
 4      * @param context
 5      * @return
 6      */
 7     public static int getBottomStatusHeight(Context context) {
 8         int totalHeight = getDpi(context);
 9 
10         int contentHeight = getScreenHeight(context);
11 
12         return totalHeight - contentHeight;
13     }

 

转载于:https://www.cnblogs.com/zimengfang/p/6372906.html

你可能感兴趣的:(Android获取虚拟软键盘高度)