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
Solution 1:
This works for me:
android:background="?android:attr/selectableItemBackground"
Solution 2:
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
Solution 3:
If you are using appcompat-v7
, you can just use ?attr/selectableItemBackground
.
Solution 4:
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.