CoordinatorLayout not drawing behind status bar even with windowTranslucentStatus and fitsSystemWindows

前端 未结 4 979
旧时难觅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条回答
  •  我在风中等你
    2020-12-23 12:54

    1. If I want to draw behind StatusBar I use CoordinatorLayout as most parent view of Activity (android:fitsSystemWindows="false")

    styles.xml(v21)

    
    

    Then If you want to change statubarcolor, you have to remove TRANSLUENT_FLAG like this

    Window window = activity().getWindow();
            if(showTransluent){
                window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.setStatusBarColor(Color.TRANSPARENT);
            }else {
                window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
                window.setStatusBarColor(ContextCompat.getColor(activity(), R.color.colorPrimaryDark));
            }
    
    1. If I want StatusBar to be transluent and simultanieousy kepping view away from hidding behind StatusBar I use as most parent view FrameLayout with argument

    My styles.xml(v21) look like

    
    
        
    
        
    
    

    And styles.xml

    
    

    Maybe the point key here is to be sure that you use AppCompactActivity as well as you use Theme.AppCompact as root for your styles.

提交回复
热议问题