Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the default drawable for pressing a list item

When the user presses a ListView item (android:state_pressed="true") it flashes a shade of yellow (or you can press and hold).

What drawable is this? I've created my own selector because I want my own ListView item color , but I lose the pressed color.

There's an Android doc about skinning buttons that references #ffff0000, but this produces red.

Does anyone know what it is and how to reference it?

like image 393
Andrew Avatar asked Aug 17 '10 21:08

Andrew


2 Answers

The default system resources can be found in <android-sdk>/platforms/android-<version>/data/res. In particular, the list selector is defined in drawable/list_selector_background.xml:

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_window_focused="false"
        android:drawable="@color/transparent" />

    <!-- Even though these two point to the same resource, have two states so the drawable will invalidate itself when coming out of pressed state. -->
    <item android:state_focused="true" android:state_enabled="false"
        android:state_pressed="true"
        android:drawable="@drawable/list_selector_background_disabled" />
    <item android:state_focused="true" android:state_enabled="false"
        android:drawable="@drawable/list_selector_background_disabled" />

    <item android:state_focused="true" android:state_pressed="true"
        android:drawable="@drawable/list_selector_background_transition" />
    <item android:state_focused="false" android:state_pressed="true"
        android:drawable="@drawable/list_selector_background_transition" />

    <item android:state_focused="true"
        android:drawable="@drawable/list_selector_background_focus" />

</selector>

The drawable that is shown on a press, list_selector_background_transition, is not a single color but two 9-patch images, a yellow and a white one, with an animated transition between them.

<transition xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:drawable/list_selector_background_pressed"  />
    <item android:drawable="@android:drawable/list_selector_background_longpress"  />
</transition>
like image 146
Jonas Avatar answered Oct 20 '22 15:10

Jonas


The thing your talking about is the Android OS built-in selector.

Make your own highlight with an xml-file in your drawable-folder like this:

<?xml version="1.0" encoding="utf-8"?>
  <selector xmlns:android="http://schemas.android.com/apk/res/android"> 
  <item android:state_pressed="true" android:color="#YOURCOLOR" /> 
  <item android:color="#FE896F" /> 
</selector>

Then in your XML-file there you have your ListView.

android:textColor="@drawable/highlight" //For text to appear like YOURCOLOR
//or if you wish the background
android:background="@drawable/highlight" //For the background to appear like YOURCOLOR

I hope this is it and tell me if this worked or not!

like image 31
Curtain Avatar answered Oct 20 '22 16:10

Curtain