Drop shadow around all the four sides of an EditText in Android Studio(在 Android Studio 中在 EditText 的所有四个边上放置阴影)
问题描述
据我所知,没有任何属性可以在 EditText 字段周围放置阴影,可以在布局文件中设置.我搜索了问题并找到了我必须提供自定义背景 xml drawable 的解决方案.
我的 drawable/background_with_shadow 看起来像这样:
我正在为我的 LinearLayout
设置此属性,其中包含一个 EditText
但是,它只会在底角和底角周围投下阴影.我将如何处理所有四个边和角?
我正在努力实现这一目标:
有一些更好的方法可以在不使用 layer-list
的情况下在编辑文本周围获得阴影:
#1
将您的 EditText
包装在 CardView
中,如下所示:
2
使用 9 补丁作为 EditText
的背景:
<EditTextandroid:id=@+id/msg_box"安卓:填充=20dp";android:background=@drawable/shadow"android:layout_width=match_parent"android:layout_height="wrap_content";android:layout_centerVertical=真"安卓:线=5";安卓:重力=顶部";android:hint="输入您的投诉..."android:textColorHint="#a7a7a7";android:textSize="15dp";/>
输出
阅读更多关于 9patch 这里.
这里是一个很棒的在线工具,可以生成 9 个补丁阴影.
As far as my knowledge aids me, there isn't any property to drop shadow around an EditText field, that can be set in the layout file. I searched for the problem and found solution that I've to provide a custom background xml drawable.
My drawable/background_with_shadow looks like this:
<?xml version="1.0" encoding="utf-8"?>
<layer-lis xmlns:android="http://schemas.android.com/apk/res/android">
<item >
<shape
android:shape="rectangle">
<solid android:color="@android:color/darker_gray" />
<corners android:radius="5dp"/>
</shape>
</item>
<item android:right="1dp" android:left="1dp" android:bottom="2dp">
<shape
android:shape="rectangle">
<solid android:color="@android:color/white"/>
<corners android:radius="5dp"/>
</shape>
</item>
</layer-list>
and I'm setting this property for my LinearLayout
which contains an EditText
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_with_shadow">
<EditText>
.
.
</EditText>
<LinearLayout>
However it just drops the shadow around the bottom and bottom corners.
How would I do it for all the four sides and corners?
I'm trying to achieve this:
解决方案 There are some better ways to get shadow around your edit text without using layer-list
:
#1
Wrap your EditText
in a CardView
like this :
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardElevation="7dp"
android:layout_margin="10dp"
app:cardCornerRadius="0dp">
<EditText
android:id="@+id/msg_box"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:hint="Write a message"
android:paddingLeft="5dp"
android:paddingStart="5dp"
android:textColorHint="#c7c7c7"
android:textSize="15dp" />
</android.support.v7.widget.CardView>
OUTPUT :
2
Use a 9 patch as the background of your EditText
:
<EditText
android:id="@+id/msg_box"
android:padding="20dp"
android:background="@drawable/shadow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:lines="5"
android:gravity="top"
android:hint="Enter your complaint..."
android:textColorHint="#a7a7a7"
android:textSize="15dp" />
OUTPUT
Read more about 9patch here.
Here's a great online tool to generate 9 patch shadow.
这篇关于在 Android Studio 中在 EditText 的所有四个边上放置阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Android Studio 中在 EditText 的所有四个边上放置阴


- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- android 4中的android RadioButton问题 2022-01-01