I use spinner to display a dropdown. I want the items in the list to have rounded corners. So I use a 9-patch containing an image with rounded corners (transparent on the outside of the corners) for the background of the view elements and a selector to display another color 9-patch when pressed.
Problem: when I click elements in the list of counters, I can see a blue background in the corners where the 9-patch is transparent.
I can not get rid of this blue background that appears when I click elements. If I remove the 9 patches and any settings in the spinner, I see that the items in the list by default are gray and blue when clicked.
I also tried not to use 9 patches as a background, but only a color selector, and set the pressed color in the selector to be transparent. Then, when I click on an item, it is not transparent, but blue. I think the view in the list is really transparent, but when you click on it the blue color still remains ...
I am using a custom SpinnerAdapter to create an element view. Here is the simplified code:
private class MySpinnerAdapter implements SpinnerAdapter {
@Override
public View getDropDownView(int i, View recycledView, ViewGroup viewGroup) {
View view = new View(context);
view.setBackground(context.getResources().getDrawable(R.drawable.testspinner));
view.setMinimumHeight(100);
return (View) view;
}
}
The selector used for the background. Here only with color, and without a 9 patch. Pressed color should be transparent:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_pressed="true"
android:drawable="@android:color/transparent" />
<item
android:drawable="@android:color/holo_purple" />
</selector>
I installed a custom adapter on the counter:
spinner.setAdapter(new MySpinnerAdapter());
And the spinner is extracted from the XML layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="wrap_content">
<Spinner
android:id="@+id/myDropDown"
android:spinnerMode="dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dropDownWidth="match_parent"/>
</LinearLayout>
I tried to set many different attributes on Spinner and tried some style attributes, but I could not get rid of this blue background ...