selector not working with layout and image view

前端 未结 5 1718
你的背包
你的背包 2021-02-01 07:10

I want to use selector for a layout and image view..But it is not working for me. When I changed image view to imagebutton or button, it works fine. Any help will be greatly app

相关标签:
5条回答
  • 2021-02-01 07:21

    For me it helped to not assign the attribute android:clickable to the layout but to the ImageView instead. I just wanted the image to be clickable though, not the containing layout.

    0 讨论(0)
  • 2021-02-01 07:24

    You have to change src to background

    or

    ImageButton to ImageView and alse write android:clickable="true"in ImageView attributes.

    0 讨论(0)
  • 2021-02-01 07:27

    I ran into this problem just now. You'll have to set the LinearLayout to clickable. You can either do this in the XML with

    android:clickable="true"
    

    Or in code with

    yourLinearLayout.setClickable(true);
    
    0 讨论(0)
  • 2021-02-01 07:30

    try this

        <selector
      xmlns:android="http://schemas.android.com/apk/res/android">
      <item android:state_focused="true" 
              android:state_pressed="false" 
              android:drawable="@drawable/lastread_ok" />
        <item android:state_focused="true" 
              android:state_pressed="true"
              android:drawable="@drawable/lastread_ok" />
        <item android:state_focused="false" 
              android:state_pressed="true"
          android:drawable="@drawable/lastread_ok_selected" />
        <item android:drawable="@drawable/lastread_ok" />
    </selector>
    

    you can use your image instead of lastread_ok & lastread_ok_selected

    0 讨论(0)
  • 2021-02-01 07:35

    use the id of imageview instead of linear layout and setclicklistener for imageview itself, it will work!!

    0 讨论(0)
提交回复
热议问题