我使用微调器显示下拉列表.
我希望列表中的项目具有圆角.
所以我使用9-patch包含带圆角的图像(角落外侧是透明的)用于视图项目背景,而选择器用于在按下时显示不同颜色的9-patch.
问题:当我按下微调器列表中的项目时,我可以在角落看到蓝色背景,其中9补丁是透明的.
我似乎无法摆脱按下项目时出现的蓝色背景.如果我删除9个补丁和微调器中的任何设置,我可以看到列表中的项目视图默认为灰色,按下时为蓝色.
我还尝试不使用9个色块作为背景,而只使用颜色选择器,并将选择器中的按下颜色设置为透明.然后当我按下项目时,它不是透明的,而是蓝色的.我认为列表中的视图非常透明,但按下时背景中仍然有蓝色…
我使用自定义SpinnerAdapter来创建项目视图.
这是简化的代码:
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;
}
}
用于背景的选择器.这里只有一种颜色,没有9补丁.压制颜色应该是透明的:
android:state_pressed="true"
android:drawable="@android:color/transparent" />
android:drawable="@android:color/holo_purple" />
我在微调器上设置自定义适配器:
spinner.setAdapter(new MySpinnerAdapter());
并且从XML布局中获取微调器:
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="wrap_content">
android:id="@+id/myDropDown"
android:spinnerMode="dropdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:dropDownWidth="match_parent"/>
我尝试在Spinner上设置许多不同的属性,并尝试了一些样式属性,但我无法摆脱这个蓝色背景……