Skip to content Skip to sidebar Skip to footer

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

Solution 1:

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:

<selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid: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. --><itemandroid:state_focused="true"android:state_enabled="false"android:state_pressed="true"android:drawable="@drawable/list_selector_background_disabled" /><itemandroid:state_focused="true"android:state_enabled="false"android:drawable="@drawable/list_selector_background_disabled" /><itemandroid:state_focused="true"android:state_pressed="true"android:drawable="@drawable/list_selector_background_transition" /><itemandroid:state_focused="false"android:state_pressed="true"android:drawable="@drawable/list_selector_background_transition" /><itemandroid: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.

<transitionxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:drawable="@android:drawable/list_selector_background_pressed"  /><itemandroid:drawable="@android:drawable/list_selector_background_longpress"  /></transition>

Solution 2:

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"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><itemandroid:state_pressed="true"android:color="#YOURCOLOR" /><itemandroid: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!

Solution 3:

A color is defined as #AARRGGBB where AA represents the alpha (transparency) value, RR the amount of red, GG the amount of green, and BB the amount of blue. Thus #ffff0000 is solid and all red. If you want orange, you want to add some green, i.e: #ffffA500. Google for RGB color values to see pages of colors with their rgb values.

Solution 4:

I have used a color picker tool in a photo editing application to find the outer and inner colors of the gradient and made my own.

<shapexmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle"><gradientandroid:startColor="#ffb300"android:centerColor="#ffc800"android:endColor="#ffb300"android:angle="270"/></shape>

Post a Comment for "What Is The Default Drawable For Pressing A List Item"