Transparent action bar and status bar like Uber

后端 未结 6 917
自闭症患者
自闭症患者 2020-12-08 03:29

I\'ve done a few researches on this topic but I couldn\'t found some solution for my App/ Activity.

  1. I have tried to get a transparent action bar.
6条回答
  •  猫巷女王i
    2020-12-08 04:00

    Try this: in your activity: Set Fullscreen Flag

        @TargetApi(Build.VERSION_CODES.LOLLIPOP)
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
            if (android.os.Build.VERSION.SDK_INT >= 21)
                getWindow().setStatusBarColor(Color.TRANSPARENT);
            super.onCreate(savedInstanceState);
        }
    

    Now in manifest: Apply theme

    
    

    in res/styles.xml

    
    

    And set android:fitsSystemWindows="false" in your CoordinatorLayout

    • fitsSystemWindows="false" : draws the view normally, under the status bar because of the window flags you have set.

    • fitsSystemWindows="true" : draws the view under the status bar because of the window flags you have set, but adds a top
      padding so that content is drawn below the status bar and they don't overlap.

提交回复
热议问题