2012-03-18 60 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”