zoukankan      html  css  js  c++  java
  • 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     }
  • 相关阅读:
    Best Time to Buy and Sell Stock
    Permutations II
    数组中最大和的子数组
    基于Socket.IO的Client封装
    Java中的ThreadLocal功能演示
    基于WebSocket的client封装
    Socket接口开发和测试实践
    自动化测试用例的原子性
    [CF1477C] Nezzar and Nice Beatmap
    [CF1477B] Nezzar and Binary String
  • 原文地址:https://www.cnblogs.com/zimengfang/p/6372906.html
Copyright © 2011-2022 走看看