Android平板电脑上的系统栏大小

Ste*_*ich 2 size android tablet

我有问题,我需要Android平板电脑系统栏的高度.这是同样的问题,因为在这里,但我不能使用这个答案,因为它给我的尺寸从DisplayMetrics相同.在这两种方式中,我都可以通过此计算得到分辨率.(这个问题不会出现在我的智能手机上,就在我的平板电脑上).

Chr*_*acy 11

// status bar (at the top of the screen on a Nexus device) 
public static int getStatusBarHeight(Context context) {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier("status_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}

// navigation bar (at the bottom of the screen on a Nexus device)
public static int getNavigationBarHeight(Context context) {
    Resources resources = context.getResources();
    int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
    if (resourceId > 0) {
        return resources.getDimensionPixelSize(resourceId);
    }
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

  • @Frank - 将不同的值作为第一个参数传递给`getIdentifier()`. (2认同)