ListViews on the golem, area unit extensively used. we tend to see them in numerous shapes and sizes, withtotally differenttypesof things, variedcolours and fonts. I wouldn’t say these customizations area unittroublesome to code, howeverthey are doing involve lots of bits and items. As youll have complete, the technique is fairly distinctive and not therefore obvious. I’ll attempt to break it up into bits and itemsthatarea unit short and hopefully sweet.
This trick involves exploitationone thingcalled android:listSelector. primarilya listing selector is employed to specify the looks of the chosen list item (I’ve appear articles suggesting that they willeven bewont tomodification the background color of individual items) which can be in one amongthe subsequent states:
android:state_focused
android:state_pressed
none of the above
Lets start by first defining the colors we’re going to use for these states.
I am going to start by defining the appearance of the selected item that has focus. This can be a simple color or a reference to a Drawable resource (e.g., PNG ). I am using a gradient shape below : listview_selector_focussed.xml:
This file binds the gradients we’ve defined in the first two code blocks with the focused and pressed state. Note that we don’t define anything for the last state i.e. none of the above. If we do not define an item for a given state the defaults are used.
The final stage is to bind the selector we defined above to the instance of the list view we’re customizing. In the xml file for the layout that contains the listview, add the following attribute:
1
<ListView
2
...
3
<!-- other attributes omitted -->
4
android:listSelector="@color/listview_selector"
5
/>
We get the following results:
When selected item has focus
When selected item is pressed
About rerea
Author Description here.. Nulla sagittis convallis. Curabitur consequat. Quisque metus enim, venenatis fermentum, mollis in, porta et, nibh. Duis vulputate elit in elit. Mauris dictum libero id justo.