How to highlight row in ListView in Android?

后端 未结 8 1492
天涯浪人
天涯浪人 2020-11-27 06:05

I need to highlight a row in a ListView that was selected (to show the user what he chose), so, it\'s not the one that is going to be chosen, it\'s the one he c

8条回答
  •  暖寄归人
    2020-11-27 06:20

    You can use transition. Follow my code because i have achieved highlighting of specific listview item by choice Lets say you want to highlight first item for 5 seconds.

     if(position == 0){
                        viewHolderThubnail.relImage.setBackgroundResource(R.drawable.translate);
                        TransitionDrawable transition = (TransitionDrawable) viewHolderThubnail.relImage.getBackground();
                        transition.startTransition(1000);
    
                    }else{
    
                        viewHolderThubnail.relImage.setBackgroundResource(R.color.white);
                    }
    

    translate.xml

    
       
              
              
              
       
    

    new_state.xml

    
    
        
    
    

    original_state.xml

    
    
        
    
    

    If you understood this code, which is very simple i must say, then the listview item at zero'th position will highlight in blue color for 5 seconds and then it will slow fade to white color.

提交回复
热议问题