Android examples for User Interface:StatusBar
get StatusBar Height via Reflection
//package com.java2s; import java.lang.reflect.Field; import android.content.Context; import android.util.Log; public class Main { private static final String TAG = "ActivityUtil"; public static int getStatusBarHeight(final Context context) { Class<?> c = null;/* w w w .j a va 2s. c o m*/ Object obj = null; Field field = null; int dp = 0; int statusBarHeight = 50; try { c = Class.forName("com.android.internal.R$dimen"); obj = c.newInstance(); field = c.getField("status_bar_height"); dp = Integer.parseInt(field.get(obj).toString()); statusBarHeight = context.getResources().getDimensionPixelSize( dp); Log.i(TAG, "Status height is: " + statusBarHeight); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (NoSuchFieldException e) { // TODO Auto-generated catch block e.printStackTrace(); } return statusBarHeight; } }