Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default selector background in Clickable Views

I have some clickable views and I want to set the default available background that is present on list click (in ICS is a blue color). I have tried putting as background this:

android:background="@android:drawable/list_selector_background"

but it is not the default blue I have by default (the one I used is orange). What is the drawable used by default on android as click selector?

Thanks

like image 283
Matroska Avatar asked Feb 12 '12 16:02

Matroska


4 Answers

This works for me:

android:background="?android:attr/selectableItemBackground"
like image 73
Bogdan Balan Avatar answered Nov 18 '22 05:11

Bogdan Balan


It's list_selector_holo_dark or the equivalent holo light version; and these are the defaults in Honeycomb and above. list_selector_background is the non-holo version, used in Gingerbread and below.

EDIT: I believe (but can't confirm) that the platform agnostic selector is ?android:attr/listSelector

like image 23
Alex Curran Avatar answered Nov 18 '22 07:11

Alex Curran


If you are using appcompat-v7, you can just use ?attr/selectableItemBackground.

like image 11
idunnololz Avatar answered Nov 18 '22 07:11

idunnololz


There is a way to combine all the valid answers:

Define a attribute (eg. in values/attrs.xml):

<attr name="clickableItemBackground" format="reference"/>

In your platform dependent theme section (eg. in values/styles.xml or values/themes.xml) declare this:

<style name="Theme.Platform" parent="@android:style/Theme.Whatever">
        <item name="clickableItemBackground">@android:drawable/list_selector_background</item>
</style>

In your platform dependent theme section for api-11+ (eg. in values-v11/styles.xml or values-v11/themes.xml) declare this:

<style name="Theme.Platform" parent="@android:style/Theme.Holo.Whatever">
        <item name="clickableItemBackground">?android:attr/selectableItemBackground</item>
</style>

Then use ?attr/clickableItemBackground wherever needed.

like image 8
flx Avatar answered Nov 18 '22 07:11

flx