Android examples for User Interface:Display
get Displayable Height
//package com.java2s; import java.lang.reflect.Method; import android.content.Context; import android.graphics.Point; import android.view.Display; import android.view.WindowManager; public class Main { private static Context context; private static boolean phone; public static int getDisplayableHeight() { return getDisplayHeight() - getStatusBarHeight(); }/* w w w .ja va2 s .co m*/ public static int getDisplayHeight() { return context.getResources().getDisplayMetrics().heightPixels; } public static int getStatusBarHeight() { int result = 0; if (isPhone() || !hasOnScreenSystemBar()) { int resourceId = context.getResources().getIdentifier( "status_bar_height", "dimen", "android"); if (resourceId > 0) { result = context.getResources().getDimensionPixelSize( resourceId); } } return result; } public static boolean isPhone() { return phone; } public static boolean hasOnScreenSystemBar() { WindowManager wm = (WindowManager) context .getSystemService(Context.WINDOW_SERVICE); Display d = wm.getDefaultDisplay(); int deviceDisplayHeight = 0; try { Method getRawHeight = Display.class.getMethod("getRawHeight"); deviceDisplayHeight = (Integer) getRawHeight.invoke(d); } catch (Exception ex) { } Point s = new Point(); d.getSize(s); int windowHeight = s.y; return deviceDisplayHeight - windowHeight > 0; } }