2012-03-18 59 views
0

我有一個ImageButton的,我發誓我把一切都樹立正確的,但它沒有顯示在按下的狀態下,不同的圖標。這是我的。安卓:ImageButton的不顯示狀態按下

的ImageButton

 <!-- HOME BUTTON --> 
    <ImageButton 
     android:id="@+id/home" 
     android:layout_width="45dp" 
     android:layout_height="fill_parent" 
     android:background="@android:color/transparent" 
     android:contentDescription="Home" 
     android:src="@drawable/title_home" 
     android:layout_alignParentLeft="true" 
     android:onClick="onClickHome" /> 

標題首頁

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/title_home_pressed"/> 
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/title_home_pressed"/> 
<item android:state_focused="true" android:drawable="@drawable/title_home_pressed"/> 
<item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/title_home"/> 
</selector> 

是的,這些都是有效的圖像,它們是不同的。 title_home是唯一正在顯示的人。

我想感謝任何想法?

回答

1

注意你是如何引用@繪製/ title_home在第一個代碼塊,但你正打算指XML文件。雖然在第二個代碼塊中,你指的是另一個@ drawable/title_home,我假設它是一個圖像。

因此,我只能假設從您的信息中您的第一塊代碼是讀取圖像而不是xml文件。爲了解決這個問題,我相信改變其中一個名字會有所幫助。

+1

你是絕對正確的!哈,有時你只需要另一套眼睛來指出明顯的! – 2012-03-18 06:26:22

0
android:src="@drawable/title_home" 

<item android:state_focused="false" android:state_pressed="false" android:drawable="@drawable/title_home"/> 

相同的名稱。將您的xml文件名更改爲title_home_btn_selector。 然後讓第一個爲

機器人:SRC = 「@繪製/ title_home_btn_selector」