Android 在按钮上设置一个xml可绘制资源文件作为背景,如何使按钮单击更可见
在按钮上设置xml可绘制资源文件作为背景时,如何使按钮的单击更像按下动画一样可见。向按钮添加背景时,不清楚按钮是否已按下。那么,有什么解决办法吗 我的可绘制资源文件Android 在按钮上设置一个xml可绘制资源文件作为背景,如何使按钮单击更可见,android,xml,button,Android,Xml,Button,在按钮上设置xml可绘制资源文件作为背景时,如何使按钮的单击更像按下动画一样可见。向按钮添加背景时,不清楚按钮是否已按下。那么,有什么解决办法吗 我的可绘制资源文件 <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:s
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="rectangle">
<solid android:color="#ca8924" />
<corners
android:radius="5dp"
/>
</shape>
</item>
<item android:left="3dp" android:right="3dp" android:top="3dp" android:bottom="3dp">
<shape android:shape="rectangle">
<corners
android:radius="5dp"
/>
<solid android:color="#5c5656">
</solid>
</shape>
</item>
</layer-list>
将此代码粘贴到drawables文件夹下的xml文件中
<?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" >
<corners android:radius="10dp" />
<stroke android:width="1dp" android:color="#33ff33" />
<gradient android:angle="-90" android:startColor="#00ff00" android:endColor="#1aff1a" />
</shape>
</item>
<item android:state_focused="true">
<shape android:shape="rectangle" >
<corners android:radius="10dp" />
<stroke android:width="1dp" android:color="#33ff33" />
<solid android:color="#1aff1a"/>
</shape>
</item>
<item >
<shape android:shape="rectangle" >
<corners android:radius="10dp" />
<stroke android:width="1dp" android:color="#33ff33" />
<gradient android:angle="-90" android:startColor="#66ff66" android:endColor="#4dff4d" />
</shape>
</item>
</selector>
选中此选项-一个单独的xml文件或我在按钮上用作背景的背景xml文件?您可以将此文件设置为按钮的背景。我是否必须将其写入一个单独的xml文件或我在按钮上用作背景的背景xml文件?只需右击drawable->drawable resource file创建一个新文件,命名文件并将上面的代码粘贴到新创建的可绘制文件中…然后将该文件设置为按钮的背景,是的,我想使用图层列表而不是选择器。我现在该怎么做?它只适用于选择器!!!。如果我惹你生气了,我很抱歉