0

I'm working on a GridView with setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL). By default, rows are not getting highlighted (with the blue highlight you see on WhatsApp or Gallery apps), so I am wondering, does the Android API already takes care of highlighting the selected items and I am missing something (if so, what am I missing?) or do I have to take care of highlighting selected rows by myself (if so, how to highlight, not just change the background)?

Here's my code:

gridView.setOnItemClickListener(this);
gridView.setEmptyView(view.findViewById(R.id.empty));
gridView.setChoiceMode(GridView.CHOICE_MODE_MULTIPLE_MODAL);

// multiChoiceModeListener is a subclass of AbsListView.MultiChoiceModeListener
// with no particular code on its abstracts methods.
gridView.setMultiChoiceModeListener(multiChoiceModeListener);
Christopher Francisco
  • 15,672
  • 28
  • 94
  • 206

1 Answers1

4

Use this for your ListItem background (XML layout)

android:background="?android:attr/activatedBackgroundIndicator"

It's basically only a selector, you can also build yourself: https://android.googlesource.com/platform/frameworks/base/+/refs/heads/master/core/res/res/drawable/activated_background.xml

EDIT:

Given your comment, this solves it:

android:foreground="?android:attr/activatedBackgroundIndicator" with a FrameLayout

Also related question: How to set foreground attribute to other non FrameLayout view

Community
  • 1
  • 1
einschnaehkeee
  • 1,858
  • 2
  • 17
  • 20