Click here to Skip to main content
15,067,335 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hey,

Im using the latest version of Android SDK and Eclipse to develop an android app.

I am using a listview to display mp3 tracks in my database.

Currently when the user presses on the name of a track the rollover colour is dark grey - see below link.

http://s30.postimg.org/vj6w4uoch/rollover.jpg

I would like to change the rollover colour to orange.

Whats the easiest way to do this?

I have tried defining it in styles.xml but fail miserably as I do not know the proper syntax.

I would be grateful for some help and advice...

Cheers
Posted
Updated 20-Jul-14 10:54am
v5

My android development is a little rusty, but all you'd need to do is change the background src of the listItem view. So add to the view.onclickListener method some code to change the background src or colour. Eg

Java
View.OnclickListener(View v){

v.setBackgroundColor(0xFF00FF00);

or

v.setBackgroundColor(Color.green);

}


therefore everytime the item is clicked the background colour will change to what ever HEX code you place in the brackets. You can change the setBackgroundColor property to a background image if you wanted if you set the view as an ImageView in your style.xml
   
v2
thanks for your reply

regretably your solution permanently fixed the background colour as per the colour specified.

the way it works is:

- create a folder in res called drawable
- place a file called hover.xml inside that folder
- set the onstate, selected and other properties to a colour of your choice
- link to this folder in your activity_main file i.e. android: list_selector ="drawable/hover"

and it works a treat :-)

thanks for your response
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900