private static int getStatusBarHeight(Context context) { int statusBarHeight = 0; Resources res = context.getResources(); int resourceId = res.getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { statusBarHeight = res.getDimensionPixelSize(resourceId); } return statusBarHeight; }
public int getStateBarHeight(Context context) { Rect rect = new Rect(); Activity activity = (Activity) context; activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect); int statusBarHeight = rect.top; return statusBarHeight; }
本文提供了两种在Android应用中获取状态栏高度的方法:一种是通过资源ID查询预定义的尺寸,另一种是通过窗口属性获取可见显示区域并计算状态栏的高度。

2378

被折叠的 条评论
为什么被折叠?



