I don't know why android:elevation
is not working
My code:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorWhite"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context=".UI.Activity.ChatActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:elevation="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.07"
app:layout_constraintStart_toStartOf="parent"
android:gravity="center_vertical">
<EditText
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="8"
android:inputType="text"
android:layout_marginLeft="15dp"
android:layout_gravity="center_vertical"
android:layout_marginRight="5dp"
android:background="@drawable/border_edit_text_messenger"
android:textCursorDrawable="@color/colorWhite"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"/>
<ImageView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.8"
android:src="@drawable/ic_send"
android:scaleType="centerInside"
android:layout_marginRight="15dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"/>
</LinearLayout>
</android.support.constraint.ConstraintLayout>
Somehow elevation does not work until you set any background color to the ViewGroup
or View
in which you want to set elevation.
Set
android:background="@color/colorWhite"
android:elevation="2dp"
to LinearLayout in your above xml.
This is default behaviour that shadow is identified by some background, so there will be NO shadow for NO background.
android:outlineProvider="bounds"
.Both above solutions will work for Android versions >21.
Solution for all versions
You can put drawable shadow on Views.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_default="percent"
app:layout_constraintHeight_percent="0.07"
app:layout_constraintStart_toStartOf="parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="4dp"
android:background="@drawable/shadow"/>
</FrameLayout>
Put showdow.xml in drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:angle="-90"
android:endColor="#33000000"
android:startColor="@android:color/transparent"/>
</shape>
You can find many ways to add shadow here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With