Charlie Wu Charlie Wu - 4 months ago 76
Android Question

AppCompatActivity remove action bar shadow with style

My app have minimum sdk 16 and I'm using

AppCompatActivity
, so I need to use
Theme.AppCompat.x
as my base theme.

I know that If I call
getSupportActionBar().setElevation(0)
, I can remove the shadow under action bar for each activity.

What I want to do is to apply this effect by using theme. Any idea to achieve this?

My main style look like this and the application uses
@style/AppTheme
.

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primary_dark</item>
</style>

Answer
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/primary_dark</item>
    <item name="actionBarStyle">@style/MyActionBarStyle</item>
    <!-- Pre-lolipop -->
    <item name="android:windowContentOverlay">@null</item>
</style>

<style name="MyActionBarStyle" parent="@style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
    <!-- remove shadow below action bar -->
    <item name="elevation">0dp</item>
</style>
Comments