沉浸式状态栏(标清版)

一、在Xml中:

 <android.support.v7.widget.Toolbar
            android:id="@+id/mToolbar"
            android:background="#f60"
            android:clipToPadding="true"
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <ImageView
                android:id="@+id/main_menu"
                android:layout_width="30dp"
                android:layout_height="30dp"
                android:src="@drawable/night"
                android:background="#ff00"
                />
<TextView
            android:text="新闻"
            android:textSize="20sp"
            android:clipToPadding="true"
            android:fitsSystemWindows="true"

            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
        </android.support.v7.widget.Toolbar>

二、在Activity中

 @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus && Build.VERSION.SDK_INT >= 19) {
            View decorView = getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }

猜你喜欢

转载自blog.csdn.net/qq_42749901/article/details/81333736