CoordinatorLayout not drawing behind status bar even with windowTranslucentStatus and fitsSystemWindows

前端 未结 4 972
旧时难觅i
旧时难觅i 2020-12-23 12:03

I am trying to draw views behind the status bar like this:

I tried to produce this effect with the recommended techniques, but I get this:

It\'s cl

4条回答
  •  -上瘾入骨i
    2020-12-23 12:30

    This was really confusing for me but I eventually figured it out for my combination of views which looks like this:

    I also used the methods posted by Budius in my app to get the transparent status bar working:

    Delete the android:windowTranslucentStatus from your XML and in Java use like that:

       public static void setTranslucentStatusBar(Window window) {
          if (window == null) return;
          int sdkInt = Build.VERSION.SDK_INT;
          if (sdkInt >= Build.VERSION_CODES.LOLLIPOP) {
             setTranslucentStatusBarLollipop(window);
          } else if (sdkInt >= Build.VERSION_CODES.KITKAT) {
             setTranslucentStatusBarKiKat(window);
          }
       }
    
      @TargetApi(Build.VERSION_CODES.LOLLIPOP)
       private static void setTranslucentStatusBarLollipop(Window window) {
          window.setStatusBarColor(
                 window.getContext()
                       .getResources()
                       .getColor(R.color. / add here your translucent color code /));
       }
    
       @TargetApi(Build.VERSION_CODES.KITKAT)
       private static void setTranslucentStatusBarKiKat(Window window) {
          window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
       }
    

提交回复
热议问题