自定义按钮选择器

时间:2014-10-12 11:05:00

标签: android button

我试图创建自定义按钮,我无法看到我的问题。

我在res / drawable / custom.xml中创建

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >

<item android:state_pressed="true" android:drawable="@drawable/forwardpress"></item>
<item android:state_focused="true" android:drawable="@drawable/forwardhover"></item>
<item android:drawable="@drawable/forward"></item>

</selector>

在main.xml上我有这个按钮

<Button
        android:id="@+id/bFor"
         android:background="@drawable/custom"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:gravity="right" />

问题是,按钮保持不带动画,(是的我在drawable文件夹中有3张不同的图片)

2 个答案:

答案 0 :(得分:0)

再次清理并构建项目。

答案 1 :(得分:0)

有趣的是,我只使用一个按钮,但另一个不按

我试试这个:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/backpress" android:state_pressed="true"/>
<item android:drawable="@drawable/back"/>

它的工作,但第二个按钮我尝试相同的过程

<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/forwardpress" android:state_pressed="true"/>
<item android:drawable="@drawable/forward"/>

</selector>

第二个按钮不起作用,很奇怪......

相关问题