按钮选择器可在触摸时不改变

时间:2013-11-23 19:02:06

标签: android android-button

我制作了一个包含3种状态的按钮选择器 - 默认,聚焦和放大启用/激活。 我的意图ID默认显示@drawable/normal;触摸/按下时@drawable/focused;启用按钮时@drawable/enabled。但它不起作用&仅显示默认(正常)可绘制。

绘制-HDPI / button_selector.xml

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

    <item android:drawable="@drawable/enabled" android:state_pressed="true"></item>
    <item android:drawable="@drawable/focused" android:state_focused="true"></item>
    <item android:drawable="@drawable/normal"></item> 

</selector>

layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    style="@style/AppBackground"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".RitualMainActivity" >

    <include layout="@layout/merge_separator" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/button_selector" />

</LinearLayout>

2 个答案:

答案 0 :(得分:1)

使用ImageButton代替imageview.Imageview默认无法点击,请参阅selector not working with layout and image view

答案 1 :(得分:0)

尝试这个....添加可点击的属性..  你可以解决问题

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clickable="true"
    android:background="@drawable/button_selector" />