The Android Toolbar overlaps the status bar/status bar changes color

  • The AndroidX Toolbar overlaps with the status bar
  • Change the status bar color:

The first Asian Games were held in New Delhi, India from 4 to 10 March 1951 under the auspices of the Asian Olympic Committee. There are Afghanistan, Myanmar, Ceylon (now Sri Lanka), Indonesia, Iran, Japan, Nepal, the Philippines, Singapore, Thailand, India and other 11 countries, athletes 489 (among them 31 women). There were 59 gold MEDALS in athletics, swimming, weightlifting, cycling, basketball and football. Japan won 26 MEDALS, Followed by India 15, Iran 8, the Philippines 5 and Singapore 5. On the eve of the opening ceremony, the Chinese sports delegation visited the Asian Games at the invitation of the Indian Sports Association without sending any athletes.

The AndroidX Toolbar overlaps with the status bar

Use: in the layout change as the Theme. AppCompat. Light. NoActionBar

Modify Toolbar and status bar do not overlap:

Android: fitsSystemWindows = “true”

Set in MainActivity

setSupportActionBar(Toolbar);

Change the status bar color:

Pass in the activity and color directly.

public static void translucentStatusBar(Activity activity, int color) {
        Window window = activity.getWindow();
        // Add Flag to set the status bar to draw mode
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        // If the mode is fully transparent, unset the Window translucent Flag
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        // Set the status bar to transparent
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.setStatusBarColor(color);
        }
        // Make the window status bar invisible
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

        // View does not adjust its layout according to the system window
        ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
        View mChildView = mContentView.getChildAt(0);
        if(mChildView ! =null) {
            ViewCompat.setFitsSystemWindows(mChildView, false); ViewCompat.requestApplyInsets(mChildView); }}Copy the code