android导航栏高度是多少?

2025-04-27 13:49:49
推荐回答(1个)
回答1:

屏幕高度都是包括了状态栏和导航栏的高度的 

2.获取控件尺寸

如果我们在onCreate()方法里直接调用getWidth()、getMeasuredWidth()获得的尺寸为0,这是由于在onCreate()中,我们的控件还没有画好,等onCreate()执行完了,我们的控件才被测量出来,我们可以注册一个监听器,用来监听测量结果

ViewTreeObserver vto  = mButton.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {            @Override
public void onGlobalLayout() {            //移除上一次监听,避免重复监听
mButton.getViewTreeObserver().removeGlobalOnLayoutListener(this);                //在这里调用getHeight()获得控件的高度
buttonHeight = mButton.getHeight();
}
});1234567891011

3.获得状态栏/通知栏的高度

public static int getStatusBarHeight(Context context){
Class c = null;
Object obj = null;
Field field = null;        int x = 0, statusBarHeight = 0;        try {
c = Class.forName("com.android.internal.R$dimen");
obj = c.newInstance();
field = c.getField("status_bar_height");
x = Integer.parseInt(field.get(obj).toString());
statusBarHeight = context.getResources().getDimensionPixelSize(x);
} catch (Exception e1) {
e1.printStackTrace();
}        return statusBarHeight;
}12345678910111213141516

4.获得导航栏高度

public int getNavigationBarHeight(Activity activity) {
Resources resources = activity.getResources();        int resourceId = resources.getIdentifier("navigation_bar_height","dimen", "android");        //获取NavigationBar的高度
int height = resources.getDimensionPixelSize(resourceId);        return height;

根据具体问题类型,进行步骤拆解/原因原理分析/内容拓展等。
具体步骤如下:/导致这种情况的原因主要是……