0

It's very strange. I already tried this steps given.

But seems no luck. Whenever I click the item inside the ListView, the item is highlighted with black color. Instead of the blue color. Which part that I wrong?

Here is my activity_chat1.xml file:

<?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" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Available Peers"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Pick one of the peers below : " />

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="128dp"
        android:listSelector="@layout/list_selection"
        android:choiceMode="singleChoice" />

    <Button
        android:id="@+id/btn_startchat"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Start to Chat" />

</LinearLayout>

and Here is my list_selection.xml file:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
   <item android:drawable="@color/pressed_color" android:state_pressed="true"/>
   <item android:drawable="@color/checked_color" android:state_selected="true"/>
</selector>

an here is my color.xml file: (under res/values directory)

<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="pressed_color">#4d90fe</color>
<color name="checked_color">#ffffff</color>
<color name="activated_color">#ffffff</color>
</resources>
Community
  • 1
  • 1
gumuruh
  • 2,544
  • 4
  • 33
  • 56

1 Answers1

1

As the comments noted move the list_selection.xml to res/drawable folder

Also change the list's listSelector:

android:listSelector="@drawable/list_selection"

And finally, the colors.xml file is supposed to be in res/values and you reference the colors by using

android:drawable="@color/pressed_color"
Simas
  • 43,548
  • 10
  • 88
  • 116