Android:ImageButton没有显示按下的状态

时间:2012-03-18 05:57:01

标签: android android-layout 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是唯一出现的人。

我很感激任何想法?

2 个答案:

答案 0 :(得分:1)

注意你在第一个代码块中引用@ drawable / title_home,但是你打算引用xml文件。虽然在第二个代码块中你指的是另一个@ drawable / title_home,我假设它是一个图像。

因此我只能假设您的第一个代码块是从您的信息中读取图像而不是xml文件。要解决这个问题,我相信更改其中一个的名称会有所帮助。

答案 1 :(得分: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”

相关问题