如何以编程方式获取 Android 导航栏的高度和宽度? [英] How do I get the height and width of the Android Navigation Bar programmatically?

查看:19
本文介绍了如何以编程方式获取 Android 导航栏的高度和宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

屏幕底部的黑色导航栏在 Android 中不容易移除.自 3.0 以来,它一直是 Android 的一部分,作为硬件按钮的替代品.这是一张图片:

The black navigation bar on the bottom of the screen is not easily removable in Android. It has been part of Android since 3.0 as a replacement for hardware buttons. Here is a picture:

如何获得此 UI 元素的宽度和高度的大小(以像素为单位)?

How can I get the size of the width and the height of this UI element in pixels?

推荐答案

试试下面的代码:

Resources resources = context.getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
    return resources.getDimensionPixelSize(resourceId);
}
return 0;

这篇关于如何以编程方式获取 Android 导航栏的高度和宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆