Android计算底部的虚拟键的高度

1.获取不含有虚拟键的高度

float heightWithOutKey = getWindowManager().getDefaultDisplay.getHeight();

2.获取含有虚拟键的高度

float heightWithKey;

Display display  = getWidnowManager().getDefaultDisplay();

DisplayMetrics metrics = new DisplayMetrics();

Class c;

try{

c = Class.forName("android.view.Display");

 Method method = c.getMethod("getRealMetrics",DisplayMetrics.class);

 method.invoke(display,metrics);

 heightWithKey = metrics.heightPixels;

}catch(ClassNotFoundException ex){

    ex.printStackTrace();

}catch(InvocationTargetException ex){

  ex.printStackTrace();

}catch(IllegalAccessException ex){

    ex.printStackTrace();

}


3.计算虚拟键的高度

float keyHeight = heightWithKey-heightWithOutKey;

你可能感兴趣的:(Android计算底部的虚拟键的高度)