android - listview custom cell seletor? -
i create custom listview cell card
but when click cell have problem
the selector display after cell, want selector display on cell. blue color fill cell range, please help.. lot
this rowshadow.xml in drawable
<?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="@android:color/darker_gray" /> <corners android:radius="0dp"/> </shape> </item> <item android:right="1dp" android:left="1dp" android:bottom="2dp"> <shape android:shape="rectangle"> <solid android:color="@android:color/white"/> <corners android:radius="0dp"/> </shape> </item> </layer-list>
and xml in layout
list_item.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="200dp" android:orientation="vertical" android:paddingtop="10dp" android:paddingleft="10dp" android:paddingright="10dp"> <relativelayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/rowshadow" > <textview android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignleft="@+id/description" android:layout_centervertical="true" android:layout_margin="5dp" android:gravity="center_vertical" android:maxlines="1" android:text="title" android:textsize="20dp" android:textstyle="bold" /> <textview android:id="@+id/description" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignparentright="true" android:layout_below="@+id/title" android:layout_margin="5dp" android:maxlines="1" android:text="textview" android:textsize="18dp" /> </relativelayout> </linearlayout>
and activity_main.xml
<?xml version="1.0" encoding="utf-8"?> <linearlayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <listview android:id="@+id/list" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/melightfgg" android:divider="@android:color/transparent" android:dividerheight="1dip" > </listview> </linearlayout>
create own selector listview , can set android:listselector="@drawable/selctor"
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <!-- when item focused. can give hex value of color directly or define color in color.xml , use here doing --> <item android:state_focused="true"><shape> <solid android:color="@color/android_blue" /> </shape></item> <!-- when item selected. can give hex value of color directly or define color in color.xml , use here doing --> <item android:state_selected="true"><shape> <solid android:color="@color/android_blue" /> </shape></item> <!-- when item pressed. can give hex value of color directly or define color in color.xml , use here doing --> <item android:state_pressed="true"><shape> <solid android:color="@color/android_blue" /> </shape></item> <!-- when item in normal state. use custom drawable or color above normal state --> <item android:drawable="@drawable/background_cell"></item> </selector>
Comments
Post a Comment