Skip to content

Instantly share code, notes, and snippets.

@mikovali
Created December 6, 2017 23:02
Show Gist options
  • Save mikovali/9e57c559bc459c932bc984b64f489090 to your computer and use it in GitHub Desktop.
Save mikovali/9e57c559bc459c932bc984b64f489090 to your computer and use it in GitHub Desktop.
Android activated item background indicator
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<selector>
<item android:state_activated="true">
<color android:color="?attr/colorControlActivated" />
</item>
</selector>
</item>
<item android:drawable="?attr/selectableItemBackground" />
</layer-list>
@mikovali
Copy link
Author

mikovali commented Dec 6, 2017

Combine selectableItemBackground and android:activatedBackgroundIndicator to have touch feedback and activated (selected) indicator.

Apply the drawable in your theme:

<item name="android:activatedBackgroundIndicator">@drawable/activated_background</item>

Then in layout add android:background="?android:attr/activatedBackgroundIndicator".
Also works when inflating android.R.layout.simple_list_item_activated_1 or android.R.layout.simple_list_item_activated_2 in adapter.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment