Android: I cannot remove elevation / shadow on my toolbar

前端 未结 10 2241
名媛妹妹
名媛妹妹 2020-12-08 01:57

Hi i would like to remove the elevation and shadow effect from my toolbar for API 21 and greater. Below is what i have tried

setSupportActionBar(mToolbar);
          


        
相关标签:
10条回答
  • 2020-12-08 02:26

    Use setOutlineProvider(null); on your appBar. Just be sure to check the SDK version. :)

    0 讨论(0)
  • 2020-12-08 02:29

    Use app:elevation="0dp" in your AppBarLayout. Make sure you put Toolbar inside your AppBarLayout like this -

        <android.support.design.widget.AppBarLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:theme="@style/AppTheme.AppBarOverlay"
            android:fitsSystemWindows="true"
            app:elevation="0dp"> 
    
            <android.support.v7.widget.Toolbar
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/firstOption"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
        </android.support.design.widget.AppBarLayout>
    

    and add this line to your activity - findViewById(R.id.appBarLayout).bringToFront();
    This will bring the AppBar to front.

    0 讨论(0)
  • 2020-12-08 02:34

    To remove elevation by using java code use the line below...

    getSupportActionBar().setElevation(0);
    
    0 讨论(0)
  • 2020-12-08 02:35

    Just remove this part of you layout hierarchy:

    <android.support.design.widget.AppBarLayout
                    android:id="@+id/appBarLayout"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">
    

    It's responsible for creating shadow. Toolbar itself doesn't cast any shadow.

    0 讨论(0)
  • 2020-12-08 02:46

    You can do that with an easy step. Don't remove the android.support.design.widget.AppBarLayout from your layout, instead add the attribute app:elevation="0dp" to it. Your final layout will be:

    <android.support.design.widget.AppBarLayout
                android:id="@+id/appBarLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:elevation="0dp">
                ...
    </android.support.design.widget.AppBarLayout>
    
    0 讨论(0)
  • 2020-12-08 02:46

    Get the appbarlayout in code:

    var appbarLayout = findviewbyid<AppBarLayout>(resource.id.  );  
    

    set the property

    appbarLayout.StateListAnimator=null;
    
    0 讨论(0)
提交回复
热议问题