具有底部边距和state_pressed的Android按钮

时间:2019-05-27 11:36:52

标签: android xml

有没有一种方法可以创建Buttonstate_pressed时具有底边距的Android false,而state_pressed为{{1}时具有不具有底边距的圆角}}?

我有这个,但是当truestate_pressed时没有底边距:

false

编辑:添加了图片

<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"> <shape android:shape="rectangle"> <solid android:color="#B5B5B5" /> <corners android:radius="10dp" /> </shape> </item> <item android:state_pressed="false"> <shape android:shape="rectangle"> <solid android:color="#FFFFFF" /> </shape> </item> </selector>

android:state_pressed="false"

1 个答案:

答案 0 :(得分:1)

<selector xmlns:android="schemas.android.com/apk/res/android"> 
<item android:drawable="@drawable/drawable_for_pressed_state" android:state_pressed="true"/> 
<item android:drawable="@drawable/drawable_for_normal_state" android:state_pressed="false"/>
</selector>

将此代码添加到可绘制文件夹中,并对不同的按钮状态使用单独的按钮可绘制对象