問題描述
據我所知,沒有任何屬性可以在 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=@dr??awable/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 的所有四個邊上放置陰影的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!