1

I apply elevation attribute and a drawable background which supply a rounded outline to the EditText View, but there is no shadow as expected.

UI in AVD

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_margin="20dp"
    android:background="#FAFAFA"
    tools:context=".MainActivity">

    <EditText
        android:id="@+id/editText"
        android:layout_width="0dp"
        android:layout_height="51dp"
        android:layout_marginTop="52dp"
        android:elevation="20dp"
        android:background="@drawable/rounded_edittext"
        android:drawableStart="@drawable/ic_search_icon"
        android:drawableLeft="@drawable/ic_search_icon"
        android:ems="10"
        android:inputType="textPersonName"
        android:paddingLeft="20dp"
        android:paddingRight="20dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.0"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/textView" />
</android.support.constraint.ConstraintLayout>

And the background rounded_edittext.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <solid android:color="#FFFFFF"/>
    <corners
        android:bottomRightRadius="27.5dp"
        android:bottomLeftRadius="27.5dp"
        android:topLeftRadius="27.5dp"
        android:topRightRadius="27.5dp"/>
    <stroke android:color="#66000000" android:width="0.5dp"/>
</shape>

UPDATE

Below is the original design.

border color #000000 opacity 10(0~100) shadow color #000000 opacity 5(0~100) UI enter image description here

Dictator
  • 105
  • 1
  • 9
  • 1
    Possible duplicate of [Add drop shadow effects to EditText Field](https://stackoverflow.com/questions/10850726/add-drop-shadow-effects-to-edittext-field) – Sunil Sunny Mar 22 '19 at 03:38

2 Answers2

2

Replace your rounded_edittext.xml with the following code:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/darker_gray" />
            <corners android:radius="27.5dp" />
        </shape>
    </item>
    <item
        android:bottom="2dp"
        android:left="1dp"
        android:right="1dp">
        <shape android:shape="rectangle">
            <solid android:color="#FFFFFF" />
            <corners android:radius="27.5dp" />
            <stroke
                android:width="0.5dp"
                android:color="#66000000" />
        </shape>
    </item>
</layer-list>

Also, replace android:elevation="20dp" from EditText with android:elevation="4dp"

RominaV
  • 3,335
  • 1
  • 29
  • 59
Kavita Patil
  • 1,784
  • 1
  • 17
  • 30
1

Go here : Android View shadow

Or if you want to a put shadow under your view, add the following

In your Layout.xml

<View android:layout_width="match_parent"
    android:layout_height="5dp"
    android:background="@drawable/dropshadow"/>

drawble/dropshadow.xml >

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <gradient android:startColor="@android:color/transparent"
        android:endColor="#88333333"
        android:angle="90"/>
</shape>
MDB
  • 131
  • 10
  • In this case, you can't directly apply the gradient as a background. You need to add the gradient background as `` in ``. – Kavita Patil Mar 22 '19 at 04:54
  • I'm not suggesting to put it as an EditText background, You have to add this in a 's Background for some effect under the perticular view so... Also i'm not using multiple items so no need to put and , try this code by putting in some xml file and use it first. – MDB Mar 22 '19 at 05:07