2014-10-12 67 views
1

我試圖創建自定義按鈕,我不能看到我的問題。自定義按鈕選擇器

我在res創建/繪製/ 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" /> 

的問題是,按鈕保持presed沒有動畫,(是的我有3個不同的圖片在可繪製的文件夾中)

回答

0

清理並再次構建您的項目。

+0

我已嘗試它無法正常工作。 thx尋求幫助 – sen 2014-10-12 11:44:31

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> 

for second button does not work,wierd ...

+0

再次清理並重新構建您的項目 – 2014-10-12 11:55:47

+0

yea man thx其工作現在像一個魅力:D和平 – sen 2014-10-12 11:58:47

+0

請接受編輯的答案;) – 2014-10-12 12:01:03