透明的系统状态栏SystemBar

透明的系统状态栏SystemBar


  • values/styles.xml

    <resources>
    
        <!-- Base application theme. -->
        <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
            <item name="colorPrimary">@color/colorPrimary</item>
            <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
            <item name="colorAccent">@color/colorAccent</item>
            <!-- Customize your theme here. -->
        </style>
    
        <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
        </style>
    
    </resources>
    
  • values-v19/styles.xml

    <resources>
    
        <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
            <item name="android:windowTranslucentStatus">true</item>
        </style>
    
    </resources>
    
  • values-v21/styles.xml

    <resources>
    
        <style name="AppTheme.NoActionBar">
            <item name="windowActionBar">false</item>
            <item name="windowNoTitle">true</item>
            <item name="android:windowDrawsSystemBarBackgrounds">true</item>
            <item name="android:statusBarColor">@color/colorPrimaryDark</item>
        </style>
    
    </resources>
    
  • layout/activity_main.xml

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/color_bg"
        tools:context=".MainActivity">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:background="@android:color/transparent"
            android:minHeight="?attr/actionBarSize">
    
            <TextView
                android:id="@+id/title"
                style="@style/TextAppearance.AppCompat.Subhead"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:text="1111"
                android:textColor="@color/colorPrimaryDark"
                android:textSize="20sp" />
        </android.support.v7.widget.Toolbar>
    
        <!--<ImageView-->
            <!--android:id="@+id/img"-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="match_parent"-->
            <!--android:scaleType="centerCrop"-->
            <!--android:src="@drawable/color_bg" />-->
    
    </RelativeLayout>
    
  • systembardemo/MainActivity.java

    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            // Translucent status bar 
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        } 
    
        setContentView(R.layout.activity_main);
    } 
    

Screenshot

I Don't Want Your Money, I Want Aragaki Yui.