Set elevation still display shadow below ActionBar

2019-08-01 10:54发布

问题:

Inside values/styles.xml I have set <item name="elevation">0dp</item> to my AppTheme style. and inside values-21/styles.xml I have set <item name="android:elevation">0dp</item> and I Have also try this <item name="android:windowContentOverlay">@null</item>.I have also try to Clean the Project and Rebuild the Project. and also try to Invalidate Caches and Restart. But my Emulator still display shadow see the below screen.

Question :

How to remove that shadow below to ActionBar.

ScreenShot :

回答1:

I don't know why elevation is not work in style. but When I set it programatically It's just work fine.

 getSupportActionBar().setElevation(0);

Output :



回答2:

If this is a pure ActionBar, and not a Toolbar. This is how you do it :

<style name="MyAppTheme" parent="Theme.AppCompat.Light">
  <item name="actionBarStyle">@style/FlatActionBar</item>
</style>

<style name="FlatActionBar" parent="Widget.AppCompat.Light.ActionBar.Solid">
  <item name="elevation">0dp</item>
</style>


回答3:

Put your toolbar in this.

<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>