public int getStatusBarHeight(Context context){ int statusBarHeight = 0; try { Class<?> clazz = Class.forName("com.android.internal.R$dimen"); Object obj = clazz.newInstance(); String heightStr = clazz.getField("status_bar_height").get(obj).toString(); //获取状态栏高度的id int heightId = Integer.parseInt(heightStr); statusBarHeight = context.getResources().getDimensionPixelSize(heightId); } catch (Exception e) { e.printStackTrace(); } return statusBarHeight; }
获取Android状态栏高度
最新推荐文章于 2022-09-20 10:37:27 发布