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;

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1. Java基础部分 基础部分的顺序:基本语法,类相关的语法,内部类的语法,继承相关的语法,异常的语法,线程的语...
    子非鱼_t_阅读 33,821评论 18 399
  • ```java /* * Copyright (C) 2006 The Android Open Source P...
    mrganer阅读 1,283评论 0 50
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 177,417评论 25 709
  • 2017年5月17日 Kylin_Wu 标注(★☆)为考纲明确给出考点(必考) 常见手机系统(★☆) And...
    Azur_wxj阅读 1,938评论 0 10
  • 奇葩说有一期的辩题是《跟机器人谈恋爱算不算爱情》。 那次辩论中,黄执中是反方,他的一个观点让我思考了很久。少爷说:...
    思语者2016阅读 1,683评论 0 1

友情链接更多精彩内容