这是我的按钮.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中的阴影颜色选项,但它不起作用。我在同一布局中有 4 个这样的按钮。提前致谢
您可以使用图层列表资源添加多个 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>
影子.xml
<item>
<shape>
<gradient
android:startColor="#000000"
android:endColor="#000000"
android:angle="270" />
<corners
android:radius="6dp" />
</shape>
</item>
</selector>
您可以根据需要在渐变中提供颜色。设置阴影.xml作为按钮背景。