When working on my own app I had a lot of trouble trying to find a complete working solution on how to change the highlight colour which is used when a list view item is selected or pressed. There are lots of examples online but I struggled to find one that demonstrated the complete solution. I have managed to get this working with the following. To begin with I have created my own theme which extends the default android one. The benefit of doing this is that I can make changes in one place and they will affect the entire application. Anything that I do not change in the theme will simply fall back to using the default settings. Create the theme in styles.xml - /res/values/styles.xml: <?xml version="1.0" encoding="utf-8"?> <resources> <style name="MyTheme" parent="android:Theme"> <item name="android:listViewStyle">@style/MyListView</item> </style> <style name="MyListView"> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">fill_parent</item> <item name="android:background">@android:color/transparent</item> <item name="android:cacheColorHint">@android:color/transparent</item> <item name="android:listSelector">@drawable/selector</item> </style> <color name="red">#ff0000</color> </resources> The only change which is made to the default theme is the list view style which is defined in the same xml file along with the colour red. The lisView style references a @drawable/selector. This must also be defined in its own xml file. /res/drawable/selector.xml: <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- When Pressed --> <item android:drawable="@drawable/selector_pressed" android:state_pressed="true"/> <!-- When Selected --> <item android:drawable="@drawable/selector_selected" android:state_selected="true" android:state_focused="false" android:state_pressed="false"/> </selector> The selector specifies two items which are used to determine what is displayed when the listView item is selected and pressed. These must also be set up in their own xml files. /res/drawable/selector_pressed.xml: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="@color/red"/> <size android:width="1dip"/> <size android:height="1dip"/> </shape> </item> </layer-list> <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="@color/red"/> <size android:width="1dip"/> <size android:height="1dip"/> </shape> </item> </layer-list> /res/drawable/selector_pressed.xml: <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="@color/red"/> <size android:width="1dip"/> <size android:height="1dip"/> </shape> </item> </layer-list> They define a rectangle which is used to highlight the selected/pressed row. The colour is set to red which was also defined in the styles.xml. The content of the two files are exactly the same which means that when selected or when pressed the item will be highlighted in red. The selector could just reference the same file for the different states but by having them in separate files it allows more control and demonstrates how it would be possible to set different colours when the item is pressed or selected. The final thing to do is update the manifest file to use the custom theme. This can be done on individual activities or on the whole application. e.g. <application android:icon="@drawable/icon" android:label="@string/app_name" android:theme="@style/MyTheme"> Hopefully if you are trying to do the same thing as me you will find this helpful.
0 Comments
VDJLastFMScrobblerV 1.0.0Java Virtual DJ – LastFM Scrobbler applicationThe LastFM scrobbler application is now available for download here. FEEDBACKYou can follow updates on the application on twitter to recieve and leave feedback.Follow @VDJScrobblefeedback@danwms.co.ukIf you have used and appreciate the scrobbler I would be grateful it if you could kindly provide a small donation. This justifies me spending more time on improving the application. Thank you This is only the first release and so there are bound to be some issues that need ironing out, I have been using it for a while and it seems to do the job. I am hoping some beta testers can try it out and give me some feedback on any issues and suggestions for improvements. I would be interested to know which versions of Virtual DJ this is confirmed to work with. In the mean time I am going to work on making it easier to install. INSTALLATION INSTRUCTIONS 1. Extract the zip file to any directory on your hard drive. 2. Right click on the ‘StartScrobbling’ file and select ‘create shortuct’. 3. Move the shortcut to somewhere more convenient e.g. desktop or the start menu. 4. Upen the vdjscrobble.properties file using any text editior 5. update the properties with your last fm username and password. 6. Update the path property with the path of the folder which container your virtual dj tracklist file. This file is normally located within your My Documents directory. 7. Save the property file. 8. Double click the shortcut to start scrobble app. once the app is running start up virtual DJ as normal and you are done. 9. When finished simply close the window. ————————————————- NOTE – The app requires the latest version of java to A link is extracted in the installation directory. ————————————————– The next version will be updated so that it does not store an unencrypted version of your password and aneasier way to configure the path. ————————————————– If you have any comments or feedback please get in touch on twitter @vdjscrobble Thank you and enjoy Last week a couple of my friends got married in Zlin. The bride (Zuzana) is from Zlin in Czech and the groom (Andy - @Andous) is from Manchester. As a surprise for Andy, Zuzana wanted to bring a bit of Manchester to Zlin for him. Andy supports Manchester Utd and is a fan of Oasis so for a bit of fun Zuzana decided to combine these two whilst showing off some sights around Manchester. Here is the video that we put together for Andy which was shown at the wedding reception (Andy is also a fan of Superman). I would just like to add that although I am a big fan of Oasis, I am not a fan of Manchester United!!
YNWA For the last 6 months I have been working on a Java application to scrobble tracks played using Virtual DJ to LastFM. The first ‘beta’ version has been ready and I have been using it to scrobble for months now but I have only just got round to setting up a site so that I am able to share it with others.
If you are a fan of LastFM and use Virtual DJ, keep an eye on this site this weekend because as soon as I have finished putting the installation instructions together Ill make the app available for download. Im after some ‘beta’ testers to help find issues and suggest possible improvements. At some point this weekend the application will be available to download from here |
MeI am a Liverpool supporting software developer originally from North Wales, now living and working in Manchester. Archives
May 2019
Categories
All
|