Android 如何为按钮创建可绘制的阴影?
我曾尝试使用9面片绘制作为图层列表,也使用了渐变,但在这两种情况下我都不能得到准确的结果,我们如何设计阴影绘制Android 如何为按钮创建可绘制的阴影?,android,gradient,drawable,nine-patch,Android,Gradient,Drawable,Nine Patch,我曾尝试使用9面片绘制作为图层列表,也使用了渐变,但在这两种情况下我都不能得到准确的结果,我们如何设计阴影绘制 您可以在 xml文件:android:elevation=“6dp” 试试这个请试试下面的drawable <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item&g
您可以在 xml文件:
android:elevation=“6dp”
试试这个请试试下面的drawable
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="180"
android:startColor="#0D4c4c4c"
android:endColor="#0D4c4c4c"
android:centerColor="#334c4c4c"
android:type="linear" />
</shape>
</item>
<item android:bottom="@dimen/_10sdp">
<shape android:shape="rectangle">
<solid android:color="#b9b9b9" />
</shape>
</item>
</layer-list>
我希望这能帮助你
谢谢。是否尝试“卡片视图”?不,我想在“按钮”中使用它。是的,但您可以在“卡片视图”中添加按钮。实际上,我已经创建了样式,我希望应用于整个应用程序,而不是在不同的.xml中进行更改。您是否尝试我的答案?实际上,我不希望动画过度绘制,我对如何设计上面提到的按钮有疑问。
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false">
<layer-list>
<!-- SHADOW -->
<item>
<shape>
<solid android:color="@color/red_400"/>
</shape>
</item>
<item
android:bottom="5px"
>
<shape>
<padding android:bottom="5dp"/>
<gradient
android:startColor="#1c4985"
android:endColor="#163969"
android:angle="270" />
<corners
android:radius="19dp"/>
<padding
android:left="10dp"
android:top="10dp"
android:right="5dp"
android:bottom="10dp"/>
</shape>
</item>
</layer-list>
</item>
</selector>
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<gradient
android:angle="180"
android:startColor="#0D4c4c4c"
android:endColor="#0D4c4c4c"
android:centerColor="#334c4c4c"
android:type="linear" />
</shape>
</item>
<item android:bottom="@dimen/_10sdp">
<shape android:shape="rectangle">
<solid android:color="#b9b9b9" />
</shape>
</item>
</layer-list>