向按钮添加彩色阴影 [英] Adding a colored shadow to a Button
本文介绍了向按钮添加彩色阴影的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要使用"from zelplin"这些属性为按钮添加阴影:
I need to add a shadow to a Button with these attributes "from zelplin":
这是设计
我尝试了这段代码
<Button
android:id="@+id/btn_sign_in"
android:layout_width="match_parent"
android:layout_height="48dp"
android:layout_marginTop="35dp"
android:background="@drawable/auth_button_shape"
android:shadowColor="#41ff4800"
android:shadowDx="0"
android:shadowDy="8"
android:text="@string/sign_in"
android:textAllCaps="true"
android:textColor="@android:color/white"
android:textSize="14sp" />
auth_button_shape
auth_button_shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#ff7c44" />
<corners android:radius="100dp" />
</shape>
但不起作用,其他属性模糊"和传播"如何为按钮设置它们.
But not worked and the other attributes "Blur" and "Spread" How I can set them for the button.
谢谢.
推荐答案
bg_test.xml
:
bg_test.xml
:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!--the shadow comes from here-->
<item
android:bottom="-6dp"
android:drawable="@android:drawable/dialog_holo_light_frame"
android:left="-6dp"
android:right="-6dp"
android:top="-6dp">
</item>
<item
android:bottom="-6dp"
android:left="-6dp"
android:right="-6dp"
android:top="-6dp">
<shape android:shape="rectangle">
<solid android:color="@color/white" />
<stroke android:width="@dimen/_1sdp" android:color="@color/yellow"/>
</shape>
</item>
Activity.xml
代码:
Activity.xml
code:
<Button
android:layout_width="@dimen/_150sdp"
android:layout_height="48dp"
android:layout_marginTop="10dp"
android:text="@string/sign_In"
android:layout_marginLeft="@dimen/_80sdp"
android:layout_gravity="center"
android:textSize="14sp"
android:background="@drawable/bg_test" />
设计按钮:
这篇关于向按钮添加彩色阴影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文