Remove android.widget.Toolbar shadow

后端 未结 10 1275
庸人自扰
庸人自扰 2021-02-02 05:34

Using API21+ Toolbar:

// Toolbar
Toolbar toolbar = new Toolbar(this);
toolbar.showOverflowMenu();

Would like to remove its shadow

相关标签:
10条回答
  • 2021-02-02 05:57
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
      appBarLayout.outlineProvider = null
    }
    
    0 讨论(0)
  • 2021-02-02 05:59

    I have found solution myself:

    getActionBar().setElevation(0);
    

    More info:

    https://developer.android.com/reference/android/app/Activity.html#getActionBar()

    0 讨论(0)
  • 2021-02-02 05:59
    findViewById(R.id.appBarLayout).bringToFront();
    

    Worked for me version issues I think Thanks Bjorn

    in this question

    0 讨论(0)
  • 2021-02-02 06:01

    Use attribute app:elevation="0dp" to your Toolbar or AppBarLayout to remove the shadow.

    #. If you are using Toolbar only, then add attribute app:elevation="0dp" to Toolbar.

        <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"
            app:elevation="0dp"/>
    

    #. If you are using AppBarLayout as a container of Toolbar, then add attribute app:elevation="0dp" to AppBarLayout.

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay"
            app:elevation="0dp">
    
            <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>
    

    OUTPUT:

    UPDATE:

    If you want to remove it programmatically then you can use below code:

    getSupportActionBar().setElevation(0);
    

    Hope this will help~

    0 讨论(0)
  • 2021-02-02 06:05

    When you add elevation 0dp on your appbarlayout, toolbar will be completely diappeared. So that you should also add translationZ in your xml.

    android:translationZ="0.1dp"
    app:elevation="0dp"
    

    Than it will look like ->

      <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/toolbarLayout"
        android:background="@android:color/transparent"
        android:translationZ="0.1dp"
        app:elevation="0dp"
        android:theme="@style/ToolbarTheme"
        >
    
        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
           />
    </com.google.android.material.appbar.AppBarLayout>
    
    0 讨论(0)
  • 2021-02-02 06:06

    Instead of android:elevation try app:elevation:

    <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/ThemeOverlay.AppCompat.Dark.ActionBar"       
        app:elevation="0dp">
    </android.support.design.widget.AppBarLayout>
    
    0 讨论(0)
提交回复
热议问题