本文主要是介绍Android获取状态栏的高度:,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
方法一:
//获取手机状态栏高度public static int getStatusBarHeight(Context context){Class<?> c = null;Object obj = null;Field field = null;int x = 0, statusBarHeight = 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());statusBarHeight = context.getResources().getDimensionPixelSize(x);} catch (Exception e1) {e1.printStackTrace();}return statusBarHeight;}
方法二:(在onResume里面获取,在onCreate 里面可能获取不到)
Rect rect = new Rect();getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);IMenu.MENU_FOOT_HEI = rect.top;
方法三:
/*** 获取状态栏高度** @param context* @return*/public static int getStatusBarHeight(Context context) {int result = 0;int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");if (resourceId > 0) {result = context.getResources().getDimensionPixelSize(resourceId);}return result;}
这篇关于Android获取状态栏的高度:的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!