首页 > 代码库 > Android下获取状态栏的高度
Android下获取状态栏的高度
/** <!-- lang: java --> * <!-- lang: java --> * @param activity <!-- lang: java --> * @return > 0 success; <= 0 fail <!-- lang: java --> */ <!-- lang: java --> public static int getStatusHeight(Activity activity){ <!-- lang: java --> int statusHeight = 0; <!-- lang: java --> Rect localRect = new Rect(); <!-- lang: java --> activity.getWindow().getDecorView( <!-- lang: java --> ).getWindowVisibleDisplayFrame(localRect); <!-- lang: java --> statusHeight = localRect.top; <!-- lang: java --> if (0 == statusHeight){ <!-- lang: java --> Class<?> localClass; <!-- lang: java --> try { <!-- lang: java --> localClass = Class.forName( <!-- lang: java --> "com.android.internal.R$dimen"); <!-- lang: java --> Object localObject = localClass.newInstance(); <!-- lang: java --> int i5 = Integer.parseInt( <!-- lang: java --> localClass.getField("status_bar_height").get( <!-- lang: java --> localObject).toString()); <!-- lang: java --> statusHeight = activity.getResources( <!-- lang: java --> ).getDimensionPixelSize(i5); <!-- lang: java --> } catch (ClassNotFoundException e) { <!-- lang: java --> e.printStackTrace(); <!-- lang: java --> } catch (IllegalAccessException e) { <!-- lang: java --> e.printStackTrace(); <!-- lang: java --> } catch (InstantiationException e) { <!-- lang: java --> e.printStackTrace(); <!-- lang: java --> } catch (NumberFormatException e) { <!-- lang: java --> e.printStackTrace(); <!-- lang: java --> } catch (IllegalArgumentException e) { <!-- lang: java --> e.printStackTrace(); <!-- lang: java --> } catch (SecurityException e) { <!-- lang: java --> e.printStackTrace(); <!-- lang: java --> } catch (NoSuchFieldException e) { <!-- lang: java --> e.printStackTrace(); <!-- lang: java --> } <!-- lang: java --> } <!-- lang: java --> return statusHeight; <!-- lang: java --> }
原文地址 http://bbs.it-home.org/thread-16887-1-1.html
Android下获取状态栏的高度
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。