Android 设置选定内容上微调器项目的背景色
我正在代码中使用控件。我希望在选择时突出显示该项目(即,该项目的背景色已更改)。如何实现这一点?为ex:mybg.xml创建一个xml:forAndroid 设置选定内容上微调器项目的背景色,android,android-layout,Android,Android Layout,我正在代码中使用控件。我希望在选择时突出显示该项目(即,该项目的背景色已更改)。如何实现这一点?为ex:mybg.xml创建一个xml:for <?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="false" android:drawable="
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="false" android:drawable="@color/anyColor" />
<item android:drawable="@android:color/transparent" />
</selector>
在您的活动xml中
做
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@color/light_grey" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@color/light_grey" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@color/light_grey" />
<item android:state_selected="true" android:drawable="@color/light_grey"/>
<item android:drawable="@color/white" />
</selector>
自定义视图布局:我的\u简单\u项目
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:lines="1"
android:padding="5dip"
android:background="@drawable/custom_selector"/>
初始化微调器:
String[] items = new String[] {"One", "Two", "Three"};
Spinner spinner = (Spinner) findViewById(R.id.mySpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.my_simple_item, items);
String[]items=新字符串[]{“一”、“二”、“三”};
微调器微调器=(微调器)findViewById(R.id.mySpinner);
ArrayAdapter=新的ArrayAdapter(此,R.layout.my_simple_项,项);
希望这有助于使用鼠标滚轮滚动时没有任何效果。项目应为浅灰色,但应为橙色(android 2.2的默认颜色),请参见我的问题
String[] items = new String[] {"One", "Two", "Three"};
Spinner spinner = (Spinner) findViewById(R.id.mySpinner);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.my_simple_item, items);