获取Android状态栏的高度
16lz
2021-12-04
通过反映的方式,获取Android系统资源的定义高度
/** * 获取到状态栏的高度 * */private int getStatusBarHeight() {Class<?> c = null;Object obj = null;Field field = null;int x = 0, sbar = 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()); sbar = getResources().getDimensionPixelSize(x); return sbar;} catch (Exception e) { e.printStackTrace();} return 0;}
更多相关文章
- 【阿里云镜像】切换阿里巴巴开源镜像站镜像——Debian镜像
- android:sharedUserId="android.uid.system" 使用系统签名+SNTP
- 「Android」在后台服务中获取前台任务包名
- android USB通信
- Android应用开发提高系列(5)——Android动态加载(下)——加载已安装A
- Android(安卓)LayoutInflater的获取及inflate()参数和返回值
- Android利用NotificationListenerService实现消息盒子功能
- android 开发之activity之间传递数据
- android中statusbar高度的问题