简体   繁体   中英

Change color of an selected ListView item

i use a default android project and try to find a way to change the background color of a listview item that got selected. I know this is done via selectors. I tried to mimic the original look and behaviour coming from the holo themes and just change the color in there, but i failed. Can somebody explain to me how to get the original look and feel for listview items (longclick fade etc) and just change the color from this strange blue to something else?

What do I have to copy to my project from android sdk and where to change the selected color?

Assuming you're using a custom ArrayAdapter , you'll have to define your onClick() listener on the second parameter of your getView() method. Usually it's called convertView , but it doesn't have to.

This second parameter, speaking very vaguely, references to the layout of each row. So when you want to change the background of your row, simply add a onClickListener() on the second parameter, and change the background:

convertView.setOnClickListener(new OnClickListener() {
  public void onClick(View v) {
    convertView.setBackground(your_new_background);
  }
}); 

dude you can use custom adapter for your listview. In custom xml files u can change everthing. For detail example follow here

I am not sure what you asking , but watever I understood I think you want something like

listview.setOnItemClickListener(new OnItemClickListener(){

 @override 
 public void onItemClick(AdapterView<?> parent, View view, int position, long id){

       ..............................
            view.setBackground("Your color");
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM