Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you get the selection color in Android?

I need to get the selection color used by Android to draw ListView and EditText selection. I know these controls user selectors to draw their states, but I've written a few widgets that I want to match the selection color of the platform they are running on and the drawables that are defined can't do that because they are using 9 patch images instead of colors.

I've looked all through the Android source and haven't found a color selector or color constant I can use to get the color I'm looking for.

like image 988
Kenny Avatar asked Oct 12 '11 19:10

Kenny


Video Answer


2 Answers

You could try this :

android:background="?android:attr/selectableItemBackground"
like image 77
lokoko Avatar answered Nov 14 '22 01:11

lokoko


you can get all the resource from here

android-sdk-windows\platforms\android-<Desire API Level>\data\res\drawable-hdpi.

or you can use directly like this

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

or like this also

Drawable d = getResources().getDrawable(android.R.drawable.list_selector_background);
like image 30
Jignesh Ansodariya Avatar answered Nov 14 '22 01:11

Jignesh Ansodariya