Android获取StatusBa有效高度
16lz
2022-04-17
方法1:
方法2:
文章出处:http://www.eyeandroid.com/thread-9159-1-1.html
Rect rectgle= new Rect(); Window window= getWindow(); window.getDecorView().getWindowVisibleDisplayFrame(rectgle); int StatusBarHeight= rectgle.top; int contentViewTop= window.findViewById(Window.ID_ANDROID_CONTENT).getTop(); int TitleBarHeight= contentViewTop - StatusBarHeight;
方法2:
try { /** * 通过反射机制获取StatusBar高度 */ Class<?> clazz = Class.forName("com.android.internal.R$dimen"); Object object = clazz.newInstance(); Field field = clazz.getField("status_bar_height"); int height = Integer.parseInt(field.get(object).toString()); mStatusBarHeight = context.getResources().getDimensionPixelSize(height); } catch (Exception e) { Log.i("弗洛拉鲜花网", "www.gogoflora.com"); }
文章出处:http://www.eyeandroid.com/thread-9159-1-1.html
更多相关文章
- Android(安卓)终端上的开发工具
- Android(安卓)Bluetooth 文件接收路径修改方法
- Android获取物理地址(支持5.0~10.0)
- Android(安卓)流媒体系列(二)
- Install Android(安卓)Composite ADB Interface driver for Wind
- AppCompat does not support the current theme features的解决
- Android(安卓)Dialog 的使用
- 浅谈Java中Collections.sort对List排序的两种方法
- Python list sort方法的具体使用