I'm developing an Android application targeting android Lollipop and above and I looked into the elevation property to achieve a shadow under the elements (namely buttons, cards and bottom navigation view).
The issue I'm facing is that when changing the android:elevation value within the XML, the shadow size is not affected. What I've tried and read:
- I've read that the elevation does not work unless the view has a background, which mine does have (posted below).
- Other problems around SO states that they do not have a shadow at all, in my case I do have a shadow under the views but its size is unaffected by the elevation property.
Concerning the code, you can find below my button style and the fragment's layout.
Button Style
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:app="http://schemas.android.com/apk/res-auto">
<style name="Search" parent="@android:style/Widget.Button">
<item name="android:gravity">center_vertical|start</item>
<item name="android:textColor">@color/lightText</item>
<item name="android:textSize">@dimen/main_search_textSize</item>
<item name="android:background">@drawable/main_search</item>
<item name="android:focusable">true</item>
<item name="android:clickable">true</item>
<item name="android:text">@string/search</item>
<item name="android:elevation">@dimen/main_search_elevation</item>
<item name="android:drawableStart">@drawable/ic_main_search</item>
<item name="android:paddingLeft">@dimen/main_search_padding</item>
<item name="android:paddingRight">@dimen/main_search_padding</item>
<item name="android:drawablePadding">@dimen/main_search_padding</item>
</style>
</resources>
Fragment Layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingStart="@dimen/activity_horizontal_margin"
android:paddingEnd="@dimen/activity_horizontal_margin"
android:background="@color/lightBackground"
android:clipToPadding="false">
<androidx.appcompat.widget.AppCompatButton
style="@style/Search"
android:layout_width="match_parent"
android:layout_height="@dimen/main_search_height"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
dimens.xml
<resources>
<dimen name="activity_horizontal_margin">24dp</dimen>
<dimen name="activity_vertical_margin">24dp</dimen>
<dimen name="main_nav_icon_padding">6dp</dimen>
<dimen name="main_search_height">54dp</dimen>
<dimen name="main_search_marginTop">72dp</dimen>
<dimen name="main_search_elevation">24dp</dimen>
<dimen name="main_search_padding">16dp</dimen>
<dimen name="main_search_textSize">20sp</dimen>
</resources>
And here's what I'm getting (no matter what the elevation property is):
Note that the shadow does change when long pressing the button, and it is not being clipped in any way.
Therefore, any idea what seems to be the issue?
