如何为Button提供阴影 [英] How to provide shadow to Button
本文介绍了如何为Button提供阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
正如您在图像中看到的,我想要在Button
后面的阴影.我创建了带有圆角的Button
.但是问题是我不能在Button
后面产生阴影.我该如何实现?
As you can see in image, I want shadow behind a Button
. I have created Button
with rounded corners. But problem is I can't generate a shadow behind that Button
. How can I achieve this?
推荐答案
使用这种方法来获得所需的外观.
button_selector.xml:
Use this approach to get your desired look.
button_selector.xml :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<layer-list>
<item android:right="5dp" android:top="5dp">
<shape>
<corners android:radius="3dp" />
<solid android:color="#D6D6D6" />
</shape>
</item>
<item android:bottom="2dp" android:left="2dp">
<shape>
<gradient android:angle="270"
android:endColor="#E2E2E2" android:startColor="#BABABA" />
<stroke android:width="1dp" android:color="#BABABA" />
<corners android:radius="4dp" />
<padding android:bottom="10dp" android:left="10dp"
android:right="10dp" android:top="10dp" />
</shape>
</item>
</layer-list>
</item>
</selector>
并在您的xml布局中:
<Button
android:background="@drawable/button_selector"
...
..
/>
这篇关于如何为Button提供阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文