Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android listview item style?

before i posted this thread , I've googled ( how to style listview items ) i cannot find a good example to showing how to style listview item ( normal , touch , long click etc ) background colors also i want to do like this VK listview with border radius and box shadow , please i really need this help also other people searching for this is there any example or can some one tell me what i have to put inside the xml selector background of the item ?

image one show how to listview item has border radius and shadow

enter image description here

image 2 showing when i click on the item

enter image description here

so guys is there any way to do like this ?

like image 538
Noob Avatar asked Jul 31 '13 21:07

Noob


People also ask

What is setAdapter in android?

A list view is an adapter view that does not know the details, such as type and contents, of the views it contains. Instead list view requests views on demand from a ListAdapter as needed, such as to display new views as the user scrolls up or down. In order to display items in the list, call setAdapter(android.

How does ListView work android?

Android ListView is a ViewGroup that is used to display the list of items in multiple rows and contains an adapter that automatically inserts the items into the list. The main purpose of the adapter is to fetch data from an array or database and insert each item that placed into the list for the desired result.

What is simple_list_item_1?

simple_list_item_1 , (a layout built into Android that provides standard appearance for text in a list), and an ArrayList called restaurants .


1 Answers

Sure, it's best to use styles here:

<!-- res/values/styles.xml -->
<style name="ListView" parent="@android:style/Widget.ListView">
    <item name="android:background">@color/light_grey</item>
    <item name="android:cacheColorHint">@android:color/transparent</item>
    <item name="android:divider">@android:color/transparent</item>
    <item name="android:dividerHeight">0dp</item>
    <item name="android:listSelector">@drawable/list_item_selector</item>
</style>

The @color/light_grey definition:

<!--- res/values/colors.xml --->
<?xml version="1.0" encoding="utf-8"?>
<resources>
   <color name="light_grey">#cccccc</color>
</resources>

You'll have to define the light_grey color in your colors.xml and create the card style list_item_selector.xml in your drawables folder:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">    
    <item android:drawable="@drawable/item_selected" android:state_pressed="true"/>
    <item android:drawable="@drawable/item_focused" android:state_focused="true"/>
    <item android:drawable="@drawable/item_normal"/> 
</selector> 
like image 55
Krylez Avatar answered Sep 19 '22 17:09

Krylez