Android获取StatusBa有效高度
16lz
2021-01-23
方法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
更多相关文章
- AppCompat does not support the current theme features的解决
- Android Bluetooth 文件接收路径修改方法
- Android中 Bitmap和Drawable相互转换的方法
- Android 处理 Button 单击事件的三种方法
- [Android Studio导入第三方类库方法] Error:(19, 23) 错误: 程序
- Android 中数据库查询方法query()中的selectionArgs的用法
- android客户端向服务器端验证登陆方法的实现2
- Unity-Android通信:AndroidJava 使用Unity c#编写Android程序调用
- Android stuio在MainActivity中运行java的main方法