how to remove shadow below actionbar with AppCompat.Light.NoActionBar?

后端 未结 10 1279
盖世英雄少女心
盖世英雄少女心 2020-12-03 00:35

I tried to remove the shadow below the toolbar with the Theme.AppCompat.Light.NoActionBar, using every recommendation of people who have ever answer it before, but no one wo

相关标签:
10条回答
  • 2020-12-03 01:25

    I had the same problem.

    If your Toolbar is inside android.support.design.widget.AppBarLayout Adding app:elevation="0dp" on android.support.design.widget.AppBarLayoutwill solve your problem.

    Else add app:elevation="0dp" on Toolbar.

    <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"
    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"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    

    Hope it helps :)

    0 讨论(0)
  • 2020-12-03 01:29

    Add app:elevation="0dp" in AppBarLayout and shadow will be hide.

    0 讨论(0)
  • 2020-12-03 01:29

    In Kotlin, use:

    supportActionBar!!.elevation = 0.0f 
    

    Regards!

    0 讨论(0)
  • 2020-12-03 01:34

    I'm not an expert but I run into the same problem just a few hours ago. So the idea here is that with AppCompat we have to manage the library attributes rather than Android attributes. In other words, 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"
        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"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
    
    </android.support.design.widget.AppBarLayout>
    

    EDIT :

    I just tried another option without AppBarLayout. This way works perfectly fine for me, the shadow is completely gone. So I suspect the problem is in your other View. I don't think it's your ToolBar drops the shadow.

    <android.support.v7.widget.Toolbar
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="?attr/actionBarSize"
        app:elevation="0dp" />
    
    0 讨论(0)
提交回复
热议问题