Open figengungor opened 8 years ago
Replace your fitSystemWindow with (Kishanjvaghela's decision): `@Override protected boolean fitSystemWindows(Rect insets) { setMyPadding(insets); return true; }
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public WindowInsets onApplyWindowInsets(WindowInsets insets) {
Rect rect = new Rect(
insets.getSystemWindowInsetLeft(),
insets.getSystemWindowInsetTop(),
insets.getSystemWindowInsetRight(),
insets.getSystemWindowInsetBottom()
);
setMyPadding(rect);
return insets.consumeSystemWindowInsets();
}
private void setMyPadding(Rect rect) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if (hasNavBar(getContext())) {
WindowManager manager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
switch (manager.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
rect.right += getNavBarWidth();
break;
case Surface.ROTATION_180:
rect.top += getNavBarHeight();
break;
case Surface.ROTATION_270:
rect.left += getNavBarWidth();
break;
default:
rect.bottom += getNavBarHeight();
}
}
}
setPadding(
rect.left, rect.top, rect.right, rect.bottom
);
}
/**
* check is system has navigation bar or not
* http://stackoverflow.com/a/29120269/3758898
*
* @param context context
* @return true if navigation bar is present or false
*/
boolean hasNavBar(Context context) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
// navigation bar was introduced in Android 4.0 (API level 14)
Resources resources = context.getResources();
int id = resources.getIdentifier("config_showNavigationBar", "bool", "android");
if (id > 0) {
return resources.getBoolean(id);
} else { // Check for keys
boolean hasMenuKey = ViewConfiguration.get(context).hasPermanentMenuKey();
boolean hasBackKey = KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_BACK);
return !hasMenuKey && !hasBackKey;
}
} else {
return false;
}
}
private int getNavBarWidth() {
return getNavBarDimen("navigation_bar_width");
}
private int getNavBarHeight() {
return getNavBarDimen("navigation_bar_height");
}
private int getNavBarDimen(String resourceString) {
Resources r = getResources();
int id = r.getIdentifier(resourceString, "dimen", "android");
if (id > 0) {
return r.getDimensionPixelSize(id);
} else {
return 0;
}
}`
You can refer my solution here. It works with gesture navigations also https://github.com/SpecialCyCi/AndroidResideMenu/issues/121#issuecomment-460137552
I changed fitSystemWindows() code with the latest update. It works fine with other devices. However, it creates a black container at the bottom of the device. How can I prevent this to happen?
The updated part in ResideMenu.java: