我正在尝试设计一个具有像这样的阴影(底部和右侧)的 EditText 字段
I am trying to design an EditText Field having Shadows (bottom and right side) like this
尝试谷歌搜索和搜索了很多 SO 讨论,但都是针对 TextView 而不是 EditText.
tried googling & hunted many SO discussions but all are for TextView not EditText.
这是我在输入文本中添加阴影而不是在文本字段中添加阴影的代码
This is my code adding shadow to Input Text but not to TextField
<EditText android:id="@+id/txtpin"
android:maxLength="4"
android:layout_marginLeft="10dp"
android:layout_height="37dp"
android:gravity="center_horizontal"
android:inputType="textPassword"
android:longClickable="false"
android:layout_width="160dp"
android:shadowColor="@color/Black"
android:shadowDx="1.2"
android:shadowDy="1.2"
android:shadowRadius="1.5"
android:background="@color/White">
<requestFocus></requestFocus>
</EditText>
<小时>
我猜它需要一些可绘制的自定义 xml 视图,但没有得到确切的想法.实现这一目标的逻辑是什么.
I guess it needs some custom xml view in drawable but not getting exact idea. What will be the logic to achieve this.
任何帮助将不胜感激.
嗯.. @Shalini 的回答以这种方式帮助了我,但我仍然有另一种方法可以使用 EditText Field 实现 2D 阴影,我将与您分享.
Well.. @Shalini's answer helped me in this way but still I got another way to achieve 2D shadow with EditText Field and I am going to share with you.
我们需要为 EditText 创建具有三层的自定义 XML 视图,底部阴影和右侧阴影
We need to create custom XML view with three layer for EditText, bottom shadow and right side shadow
下面是我的代码.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- most important is order of layers -->
<!-- Bottom right side 2dp Shadow -->
<item >
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<!-- Bottom 2dp Shadow -->
<item>
<shape android:shape="rectangle">
<solid android:color="#000000" />
</shape>
</item>
<!-- White Top color -->
<item android:bottom="3px" android:right="3px">
<shape android:shape="rectangle">
<solid android:color="#FFFFFF" />
</shape>
</item>
</layer-list>
<小时>
现在我们可以使用Background"属性将此阴影视图设置为我们的 TextField
Now we can set this shadow view to our TextField using "Background" property
喜欢这个
<EditText android:layout_width="wrap_content"
android:id="@+id/txtpin"
android:maxLength="4"
android:layout_height="37dp"
android:gravity="center_horizontal"
android:longClickable="false"
android:padding="2dp"
android:inputType="textPassword|number"
android:password="true"
android:background="@drawable/edittext_shadow"
android:layout_weight="0.98"
android:layout_marginLeft="15dp">
<requestFocus></requestFocus>
</EditText>
<小时>
结果屏幕就像我在上面发布的问题一样.
and the result screen is like I have posted in question above.
感谢 SO,分享知识.
Thanks to SO, sharing knowledge.
这篇关于向 EditText 字段添加阴影效果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!