How to remove the shadow above the app bar?

前端 未结 4 1035
生来不讨喜
生来不讨喜 2021-02-09 10:27

I\'d like to make the status bar transparent by adding @android:color/transparent to v21/styles.xml on

相关标签:
4条回答
  • 2021-02-09 11:04

    Add elevation 0dp to AppBarLayout

    <android.support.design.widget.AppBarLayout
    android:id="@+id/app_bar_layout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:elevation="0dp">
    
    0 讨论(0)
  • 2021-02-09 11:10

    Call below method in the onCreate of your activity with the desired status bar color.

    public void changeStatusBarColor(String hexColor)
      {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.parseColor("#AD2525"));
        }
     }
    

    XML

    <?xml version="1.0" encoding="utf-8"?><android.support.design.widget.CoordinatorLayout 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:fitsSystemWindows="true"
    tools:context="com.example.bharath.myapplication.MainActivity">
    
    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />
    
    </android.support.design.widget.AppBarLayout>
    
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#AD2525"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">
        <!--
        Other views
        -->
    
    </RelativeLayout></android.support.design.widget.CoordinatorLayout>
    

    Result

    0 讨论(0)
  • 2021-02-09 11:15

    I believe this question is pointing to same problem Android appbarlayout elevation appears in status bar

    Possible solutions:

    Your root layout should have android:fitsSystemWindows="true" at all times, otherwise your UI will not draw behind status bar.

    Now wrap the AppBarLayout inside another CoordinatorLayout which has

    android:fitsSystemWindows="false".

    This will prevent the shadow from overflowing into statusbar.

    0 讨论(0)
  • 2021-02-09 11:17
    <com.google.android.material.appbar.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:elevation="0dp"
                android:theme="@style/AppTheme.AppBarOverlay">
    
                <androidx.appcompat.widget.Toolbar
                    android:id="@+id/toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="?attr/actionBarSize"
                    android:background="@color/colorPrimaryDark"
                    app:popupTheme="@style/AppTheme.PopupOverlay"
                     />
    
     </com.google.android.material.appbar.AppBarLayout>
    
    0 讨论(0)
提交回复
热议问题