这是我用来获取导航栏大小的代码.它的高度将在Point.y中

public static Point getNavigationBarSize(Context context) {

Point appUsableSize = getAppUsableScreenSize(context);

Point realScreenSize = getRealScreenSize(context);

// navigation bar on the right

if (appUsableSize.x < realScreenSize.x) {

return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);

}

// navigation bar at the bottom

if (appUsableSize.y < realScreenSize.y) {

return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);

}

// navigation bar is not present

return new Point();

}

public static Point getAppUsableScreenSize(Context context) {

WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

Display display = windowManager.getDefaultDisplay();

Point size = new Point();

display.getSize(size);

return size;

}

public static Point getRealScreenSize(Context context) {

WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);

Display display = windowManager.getDefaultDisplay();

Point size = new Point();

if (Build.VERSION.SDK_INT >= 17) {

display.getRealSize(size);

} else if (Build.VERSION.SDK_INT >= 14) {

try {

size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);

size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);

} catch (IllegalAccessException e) {} catch (InvocationTargetException e) {} catch (NoSuchMethodException e) {}

}

return size;

}

编辑:要回答你的问题,我必须使用此功能,因为我想将ResideMenu添加到我的应用程序,但由于导航栏,我的应用程序底部结束了一个奇怪的空边距.

所以我编辑了Re​​sideMenu添加的这个函数,如下所示:

@Override

protected boolean fitSystemWindows(Rect insets) {

// Applies the content insets to the view's padding, consuming that content (modifying the insets to be 0),

// and returning true. This behavior is off by default and can be enabled through setFitsSystemWindows(boolean)

// in API14+ devices.

int bottomPadding = insets.bottom;

Point p = getNavigationBarSize(getContext());

if (Build.VERSION.SDK_INT >= 21 && p.x != 0) {

Resources resources = getContext().getResources();

int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");

if (resourceId > 0) {

bottomPadding += resources.getDimensionPixelSize(resourceId);

}

}

this.setPadding(viewActivity.getPaddingLeft() + insets.left, viewActivity.getPaddingTop() + insets.top,

viewActivity.getPaddingRight() + insets.right, viewActivity.getPaddingBottom() + bottomPadding);

insets.left = insets.top = insets.right = insets.bottom = 0;

return true;

}

希望能帮到你.

android导航栏高度开启,如何在Android中真正获得导航栏高度相关推荐

  1. 如何在WooCommerce中添加免费送货栏

    Do you offer free shipping on your WooCommerce store? 你们在WooCommerce商店提供免费送货吗? Offering free shippin ...

  2. android 高度百分比,如何在Android中进行百分比高度和宽度?

    现在,可以用Guidelines定位百分比值 xmlns:android="http://schemas.android.com/apk/res/android" xmlns:ap ...

  3. android 文本后图标_如何在Android中更改文本,图标等的大小

    android 文本后图标 Let's face it: no matter how good the screens are on our phones and tablets, the text ...

  4. android 工具栏沉浸 下拉,如何在Android应用中实现一个沉浸式状态栏效果

    如何在Android应用中实现一个沉浸式状态栏效果 发布时间:2020-12-08 17:04:42 来源:亿速云 阅读:151 作者:Leah 这篇文章将为大家详细讲解有关如何在Android应用中 ...

  5. android studio点击图片,如何在Android Studio中的模拟器图库中添加图像?

    如何在Android Studio中的模拟器图库中添加图像? 我正在开发图像过滤器应用程序. 但是,如果我没有任何图像,就无法真正尝试. 我知道我可以在电话中对其进行测试,但这并不相同,因为我需要错误 ...

  6. android 泰文ttf字体,如何在Android上正确显示泰语diactirics?

    简短的序言.泰语字母有可能出现在辅音上方的元音符号,并且在辅音上方也存在变音符号(DS).当元音和DS出现时,它们出现一个在另一个之上,所以元音被设置在辅音之上并且DS被设置在元音之上.如何在Andr ...

  7. android开发使用c+_如何在Android项目中开始使用C ++代码

    android开发使用c+ by Onur Tuna 通过Onur Tuna 如何在Android项目中开始使用C ++代码 (How to start using C++ code in your ...

  8. android 调出键盘表情_如何在Android的G板键盘中搜索表情符号和GIF | MOS86

    老实说,这里是1010mh1112 GIF和表情符号是新形式的沟通.像他们似乎愚蠢的,他们以某种方式添加了一个额外的层次,我们与朋友和家人通过文本或即时消息交互的方式,否则可能会干燥.虽然表情符号长期 ...

  9. android开发 转跳功能,如何在Android中利用Intent实现一个页面跳转功能

    如何在Android中利用Intent实现一个页面跳转功能 发布时间:2021-02-20 17:06:31 来源:亿速云 阅读:113 作者:Leah 本篇文章为大家展示了如何在Android中利用 ...

最新文章

  1. 漫画:前端发展史的江湖恩怨情仇
  2. 同余(数论) AcWing算法课
  3. 版本控制系统 之一 概念、分类、常见版本控制系统(CVS、SVN、BitKeeper、Git 等)
  4. 用c语言编辑一个通讯录,C语言实现一个通讯录
  5. 安装navicat之后双击就会闪退_Adobe 2020版本,安装教程来咯
  6. STL训练 HDU - 1716 Ray又对数字的列产生了兴趣:
  7. AS3 XML全部用法
  8. 如何保持交互的可见性
  9. Head First设计模式之命令模式
  10. 使用src.rpm包安装软件
  11. Maven下载及安装教程
  12. 吉木萨尔县文化旅游策划案——天山圣地,武侠之都!
  13. 禾瘦美学馆告诉你女人为什么得有曲线?
  14. 樊登读书会2016年推荐书目汇总
  15. AR涂涂乐⭐七、(end)取消“识别成功”提示面片、加入太阳系及其交互功能、退出按钮设置
  16. 抢红包算法 c++_“抠抠族”的出行利器,斤斤计较的几何C为了节能果然够拼
  17. PPT基础(一)怎么把图片设置为背景
  18. SAP中通过格式调整解决导出EXCEL表字段显示不全问题
  19. ubuntu 终端常用命令大全
  20. Django的列表分页

热门文章

  1. ios微内核和鸿蒙微内核,华为发布基于微内核、面向全场景的分布式操作系统:鸿蒙OS...
  2. 解决Driver/library version mismatch
  3. MAT(Memory Analyzer Tool)工具入门介绍
  4. 大数据学习笔记28:MR案例——多输出源处理成绩
  5. 【BZOJ3551】Peaks加强版,主席树+kruskal重构+dfs序+倍增思想
  6. 【BZOJ2326】【codevs2314】数学作业,第100篇博文纪念
  7. [noip2017]列队 splay
  8. php mysql_fetch_array 不要0_1_php – mysql_fetch_array不适用于1行查询结果
  9. redis的zset的底层实现_Redis底层数据结构之 zset
  10. 复数正弦波 matlab,为什么正弦,反正弦函数计算结果会出现复数?