这是我的Button.xml文件:
<Button android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#ffffff"
android:id="@+id/tv4"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_below="@id/tv3"
android:textStyle="bold"
android:text="Contact"
android:background="@drawable/custom_button"
android:textSize="24sp"
android:typeface="serif"
android:layout_marginTop="2dip"
android:layout_marginBottom="2dip"/>
这是我的custom_button.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape>
<gradient
android:startColor="#48b7f4"
android:endColor="#48b7f4"
android:angle="270" />
<!--stroke
android:width="1dp"
android:color="#000000" /-->
<corners
android:radius="6dp" />
</shape>
</item></selector>
如何为我的按钮添加阴影效果?我在xml中尝试过shadowcolor选项,但它无效。我有4个这样的按钮在相同的布局。提前致谢
答案 0 :(得分:1)
您可以使用图层列表资源添加多个xml文件,例如堆栈。 shadow_button.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/shadow"/>
<item
android:drawable="@drawable/custom_button"
android:bottom="4px"
android:right="4px"/>
</layer-list>
shadow.xml
<item>
<shape>
<gradient
android:startColor="#000000"
android:endColor="#000000"
android:angle="270" />
<corners
android:radius="6dp" />
</shape>
</item>
</selector>
您可以根据需要在渐变中提供颜色。将shadow.xml设置为按钮背景。