Solve the problem that android display content is blocked by the bottom navigation bar

  • 2021-09-24 23:33:26
  • OfStack

Description:

The best solution is to use AndroidBug 5497Workaround. assistActivity (this)

However, Huawei and Meizu mobile phone systems come with bottom navigation bars, which will cause some layouts to be blocked.

Solution: Add android: windowDrawsSystemBarBackgrounds "in style. xml of values-21 and set the value to false as follows

Add android: windowDrawsSystemBarBackgrounds to the subject referenced by style and set the value to false, which will automatically remind you that clicking alt+Enter will create a new folder of values-21 and generate a file of styles. xml.

If you can ignore it yourself, you can directly create a new folder of values-21 and then create a new file of styles. xml, copy the contents of the theme to styles. xml, and then add android: windowDrawsSystemBarBackgrounds "and set the value to false.

Exception: Attached (found online)


public class AndroidBug5497Workaround {
 
 // For more information, see https://code.google.com/p/android/issues/detail?id=5497
 // To use this class, simply invoke assistActivity() on an Activity that already has its content 
 
view set.
 
 public static void assistActivity (Activity activity) {
 new AndroidBug5497Workaround(activity);
 }
 private Activity activity;
 private View mChildOfContent;
 private int usableHeightPrevious;
 private FrameLayout.LayoutParams frameLayoutParams;
 
 private AndroidBug5497Workaround(Activity activity) {
 this.activity = activity;
 FrameLayout content = (FrameLayout) activity.findViewById(android.R.id.content);
 mChildOfContent = content.getChildAt(0);
 mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new 
 
ViewTreeObserver.OnGlobalLayoutListener() {
  public void onGlobalLayout() {
  possiblyResizeChildOfContent();
  }
 });
 frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
 }
 
 private void possiblyResizeChildOfContent() {
 int usableHeightNow = computeUsableHeight();
 LogUtils.e("possiblyResizeChildOfContent","usableHeightNow:"+usableHeightNow);
 LogUtils.e("possiblyResizeChildOfContent","usableHeightPrevious:"+usableHeightPrevious);
 if (usableHeightNow != usableHeightPrevious) {
  int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
 
  // This judgment is to solve the problem 19 Previous versions did not support immersive status bar, which led to incomplete layout display 
  if(Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT){
  Rect frame = new Rect();
  activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
  int statusBarHeight = frame.top;
  usableHeightSansKeyboard -= statusBarHeight;
  }
  int heightDifference = usableHeightSansKeyboard - usableHeightNow;
  if (heightDifference > (usableHeightSansKeyboard/4)) {
  // keyboard probably just became visible
  frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
  } else {
  // keyboard probably just became hidden
  frameLayoutParams.height = usableHeightSansKeyboard;
  }
  mChildOfContent.requestLayout();
  usableHeightPrevious = usableHeightNow;
 }
 }
 
 private int computeUsableHeight() {
 Rect frame = new Rect();
 activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(frame);
 int statusBarHeight = frame.top;
 
 Rect r = new Rect();
 mChildOfContent.getWindowVisibleDisplayFrame(r);
 
 // This judgment is to solve the problem 19 In later versions, when the soft keyboard is popped up, the layout of the keyboard and pushed up ( adjustResize ) with a black area between 
 
 The question of 
 if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
  return (r.bottom - r.top)+statusBarHeight;
 }
 
 return (r.bottom - r.top);
 }
 
}

Related articles: