2013.04.16——— android 获取状态栏高度

2013.04.16——— android 获取状态栏高度


public int getStatusBarHeight(){
//		Rect rect= new Rect();
//		
//		Window window= ((Activity) context).getWindow();
//		window.getDecorView().getWindowVisibleDisplayFrame(rect);
//		System.out.println(rect.top);
//		return rect.top;
		
		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 = context.getResources().getDimensionPixelSize(x); 
		} catch(Exception e1) {     
			e1.printStackTrace(); 
		}
		return sbar;
	}

猜你喜欢

转载自trylovecatch.iteye.com/blog/1848293