Android中状态栏的高度[重复]

2024-04-25

Android状态栏的高度是多少?总是一样吗?

从我的测量来看,它似乎是 25dp,但我不确定它在所有平台上是否具有相同的高度。

(我想知道这一点以正确实现从没有状态栏的活动到有状态栏的活动的淡入淡出过渡)


这个问题之前已经回答过...状态栏的高度? https://stackoverflow.com/questions/3355367/height-of-statusbar/3356263#3356263

Update::

当前方法:

好的,状态栏的高度取决于屏幕尺寸,例如在设备中 对于 240 X 320 屏幕尺寸的设备,状态栏高度为 20 像素;对于 320 X 480 屏幕尺寸的设备,状态栏高度为 25 像素;对于 480 x 800 的设备,状态栏高度必须为 38 像素

所以我建议使用这个脚本来获取状态栏高度

Rect rectangle = new Rect();
Window window = getWindow();
window.getDecorView().getWindowVisibleDisplayFrame(rectangle);
int statusBarHeight = rectangle.top;
int contentViewTop = 
    window.findViewById(Window.ID_ANDROID_CONTENT).getTop();
int titleBarHeight= contentViewTop - statusBarHeight;

   Log.i("*** Elenasys :: ", "StatusBar Height= " + statusBarHeight + " , TitleBar Height = " + titleBarHeight); 

(旧方法)获取状态栏的高度onCreate()您的 Activity 的方法,请使用此方法:

public int getStatusBarHeight() { 
      int result = 0;
      int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
      if (resourceId > 0) {
          result = getResources().getDimensionPixelSize(resourceId);
      } 
      return result;
} 
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Android中状态栏的高度[重复] 的相关文章

随机推荐