软按钮栏尺寸 [英] Dimension of soft buttons bar
问题描述
有没有一种方法来确定设备没有硬菜单按钮在菜单栏的尺寸(宽)? (如ARCHOS设备)。
Is there a way to determine the dimension (width) of the menu bar of devices without hard menu buttons? (like the archos devices).
我需要知道屏幕的可用尺寸...
I need to know the usable dimension of the screen...
谢谢, Direz
推荐答案
这个方法是为了设置在Android的奇巧布局填充(4.4)非常有用。用这种方法,就可以避免软按钮栏重叠在你的布局。
This method is very useful in order to set the layout padding in Android KitKat (4.4). Using this, you can avoid the soft buttons bar overlapping over your layout.
在 getRealMetrics
方法仅适用于API 17 +,但我只用下面的方法我写的设备上的API 19 +
The getRealMetrics
method is only available with API 17 and +, but I'm only using the following method I wrote for devices on API 19+
@SuppressLint("NewApi")
private int getSoftbuttonsbarHeight() {
// getRealMetrics is only available with API 17 and +
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int usableHeight = metrics.heightPixels;
getWindowManager().getDefaultDisplay().getRealMetrics(metrics);
int realHeight = metrics.heightPixels;
if (realHeight > usableHeight)
return realHeight - usableHeight;
else
return 0;
}
return 0;
}
测试后的Nexus 5和的Nexus 7 2013。
Tested upon Nexus 5 & Nexus 7 2013.
这篇关于软按钮栏尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!