Activity behind hardware controls
gchristov opened this issue · 3 comments
gchristov commented
gchristov commented
For anyone looking for a workaround, here's something..
After you initialize your RESideMenu, run this, which will automatically add any missing padding based on the navigation type.
// Fix RESideMenu bottom layout bug.
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
boolean hasHomeKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_HOME);
if (hasBackKey || hasHomeKey) { // There's a navigation bar.
resideMenu.postDelayed(new Runnable() {
@Override
public void run() {
Resources resources = getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
int paddingBottom = resideMenu.getPaddingBottom();
paddingBottom += resources.getDimensionPixelSize(resourceId);;
resideMenu.setPadding(resideMenu.getPaddingLeft(), resideMenu.getPaddingTop(), resideMenu.getPaddingRight(), paddingBottom);
}
}, 300);
}
hubdestro commented
Most stable solution after hard work
public Point getNavigationBarSize(Context context) {
Point appUsableSize = getAppUsableScreenSize(context);
Point realScreenSize = getRealScreenSize(context);
// navigation bar on the right
if (appUsableSize.x < realScreenSize.x) {
return new Point(realScreenSize.x - appUsableSize.x, appUsableSize.y);
}
// navigation bar at the bottom
if (appUsableSize.y < realScreenSize.y) {
return new Point(appUsableSize.x, realScreenSize.y - appUsableSize.y);
}
// navigation bar is not present
return new Point();
}
public Point getAppUsableScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
return size;
}
public Point getRealScreenSize(Context context) {
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
Point size = new Point();
if (Build.VERSION.SDK_INT >= 17) {
display.getRealSize(size);
} else if (Build.VERSION.SDK_INT >= 14) {
try {
size.x = (Integer) Display.class.getMethod("getRawWidth").invoke(display);
size.y = (Integer) Display.class.getMethod("getRawHeight").invoke(display);
} catch (IllegalAccessException e) {} catch (InvocationTargetException e) {} catch (NoSuchMethodException e) {}
}
return size;
}
And set padding of main layout
setPadding(getPaddingLeft(),
getPaddingTop(), getPaddingRight(),
getNavigationBarSize(getContext()).y);
wondersoftwares671 commented
The Simple solution that is working for me for now is,
Get Navigation bar height and set padding to root layout of activity in OnCreate() after setContentView.
.....
int navHeight = getNavHeight();
if (navHeight > 0) {
(findViewById(R.id.rlMain)).setPadding(0, 0, 0, navHeight);
}
.....
private int getNavHeight() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT)
return 0;
try {
Resources resources = getResources();
int resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
return resources.getDimensionPixelSize(resourceId);
}
} catch (Exception ex) {
return 0;
}
return 0;
}