Change Selection in a ListView from Orange to Green

后端 未结 5 1172
半阙折子戏
半阙折子戏 2020-12-24 02:27

How do I do this per selected list item.

I tried adding this to android:background



        
5条回答
  •  离开以前
    2020-12-24 03:03

    Jax, you said that:

    The problem is that the black_alpha will apply the the entire list, not just the selected list item

    I had the same problem. After playing around with it for a while, I was able to get it to stop applying the color to the whole list by using a 3x3 png image of the color I wanted instead of applying a color. So for some weird reason if you use a color you get the odd background behavior, when you use a png, it works fine. :S

    So that is one way to get around it.

    -----Another way----------

    I found the best results when I set the listView selector to not have any states like this:

    res/drawable/list_selector.xml

    
    
    
    

    Then I take care of all the states in the background of the list item. NOT in the selector. I found I had more control this way.

    res/color/list_item_bg.xml

    
       
    
    
    
    

    Then here is my list item:

    res/layout/simple_list_item.xml

    
    
      
     
    
    

提交回复
热议问题