Android Completely transparent Status Bar?

前端 未结 28 2724
旧时难觅i
旧时难觅i 2020-11-22 14:10

I\'ve searched the documentation but only found this: Link. Which is used to make the bar translucent? What I\'m trying to do is to make t

相关标签:
28条回答
  • 2020-11-22 14:14

    The following code will make your status bar along with the navigation bar transparent (note that this will make your layout a full screen layout like the layouts used in games):

    @Override
    public void onWindowFocusChanged(boolean hasFocus) {
        super.onWindowFocusChanged(hasFocus);
        if (hasFocus) {
            hideSystemUI();
        }
    }
    
    private void hideSystemUI() {
        // Enables sticky immersive mode.
        // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE_STICKY.
        // Or for regular immersive mode replace it with SYSTEM_UI_FLAG_IMMERSIVE
        View decorView = getWindow().getDecorView();
        decorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                        // Set the content to appear under the system bars so that the
                        // content doesn't resize when the system bars hide and show.
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        // Hide the nav bar and status bar
                        | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_FULLSCREEN);
    }
    

    To learn more, visit this link.

    0 讨论(0)
  • 2020-11-22 14:15

    You can use this below code.

    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); 
    getWindow().setStatusBarColor(Color.TRANSPARENT);
    

    Include this layout in your main layout.

    toolbar.xml

    <?xml version="1.0" encoding="utf-8"?>
    <androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/toolbarNav"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            app:contentInsetEnd="0dp"
            app:contentInsetLeft="0dp"
            app:contentInsetRight="0dp"
            app:contentInsetStart="0dp">
    
            <RelativeLayout
                android:id="@+id/rlBackImageLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:background="@drawable/main_background2">  //add your color here
    
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/_40sdp"
                    android:layout_marginTop="@dimen/_16sdp"
                    android:orientation="horizontal">
    
                    <ImageView
                        android:id="@+id/toolbarIcon"
                        android:layout_width="@dimen/_30sdp"
                        android:layout_height="@dimen/_30sdp"
                        android:layout_gravity="center"
                        android:layout_marginStart="@dimen/_10sdp"
                        android:padding="@dimen/_5sdp"
                        android:src="@drawable/nav_icon" />
    
                    <TextView
                        android:id="@+id/txtTitle"
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:layout_gravity="center"
                        android:layout_marginEnd="@dimen/_30sdp"
                        android:fontFamily="@font/muli_semibold"
                        android:gravity="center"
                        android:textColor="#fff"
                        android:textSize="@dimen/_14ssp"
                        android:textStyle="bold"
                        tools:text="test Data" />
    
                </LinearLayout>
    
            </RelativeLayout>
    
        </androidx.appcompat.widget.Toolbar>
    

    Note: You can replace SDP and SSP with dp and sp respectively.

    0 讨论(0)
  • 2020-11-22 14:18

    in my case as I've a bottom tool bar I had a problem when testing the previous solutions, the android system buttons are covered with my bottom menu my solution is to add within the activity:

    protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);

        // force full screen mode
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    
    
        setContentView(R.layout.main_activity_container);
    
    0 讨论(0)
  • 2020-11-22 14:19
     <item name="android:statusBarColor" tools:targetApi="lollipop">@android:color/transparent</item>
                <!--<item name="android:windowLightStatusBar" tools:targetApi="m">true</item>-->
    

    Dont use windowLightStatusBar use instead statusBarColor = @android:color/transparent

    0 讨论(0)
  • 2020-11-22 14:21

    This worked for me:

    <item name="android:statusBarColor">@android:color/transparent</item>
    <item name="android:navigationBarColor">@android:color/transparent</item>
    <item name="android:windowTranslucentStatus">false</item>
    <item name="android:windowTranslucentNavigation">false</item>
    
    0 讨论(0)
  • 2020-11-22 14:22

    Try the following code:

    private static void setStatusBarTransparent(Activity activity) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
            activity.getWindow(). setStatusBarColor(Color.TRANSPARENT);
        } else {
            activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }
    
    0 讨论(0)
提交回复
热议问题