[英]android:How to show drop shadow on an EditText view?
I apply elevation attribute and a drawable background which supply a rounded outline to the EditText View
, but there is no shadow as expected. 我应用了height属性和一个可绘制的背景,这些背景为EditText View
提供了圆形的轮廓,但是没有期望的阴影。
<?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 和背景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) 边框颜色#000000不透明度10(0〜100)阴影颜色#000000不透明度5(0〜100)
Replace your rounded_edittext.xml with the following code: 将您的rounded_edittext.xml替换为以下代码:
<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:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
<corners
android:radius="27.5dp"/>
<stroke android:color="#66000000" android:width="0.5dp"/>
</shape>
</item>
Also, replace android:elevation="20dp"
from EditText with android:elevation="4dp"
此外,更换android:elevation="20dp"
与EditText上 android:elevation="4dp"
Go here : Android View shadow 转到此处: Android View阴影
Or if you want to a put shadow under your view, add the following 或者,如果您想在视图下放置阴影,请添加以下内容
In your Layout.xml 在您的Layout.xml中
<View android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@drawable/dropshadow"/>
drawble/dropshadow.xml > 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.