1

I have a grid view in my activity. I have set the item highlight color of the grid view with GridView.setSelector().

XML

    <GridView
        android:id="@+id/gridView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal"
        android:layout_marginTop="10dp"
        android:background="#DDDDDD"
        android:choiceMode="singleChoice"
        android:columnWidth="@dimen/category_edit_grid_item_size"
        android:numColumns="auto_fit"
        android:stretchMode="columnWidth" />

Code

gridView.setSelector(R.color.theme_primary);

When I select an item, it gets highlighted in R.color.theme_primary. But as soon as I move to another input element in the activity (say I touched on an edit text), the grid view highlight goes away.

How can I keep the highlight even after grid view looses focus?

Lahiru Chandima
  • 22,324
  • 22
  • 103
  • 179

1 Answers1

1

One solution would be to use a custom state for the item that you want to keep highlighted. You can see this answer for how to add a state. After adding the state simply add logic for determining when to enable/disable that state.

Community
  • 1
  • 1
Jim Baca
  • 6,112
  • 2
  • 24
  • 30