【发布时间】:2013-06-18 14:03:58
【问题描述】:
我是安卓新手..所以需要一些帮助.. 我有一个带有白色背景的 xml 页面..其中有一个微调器..解析后值填充在该微调器中..但问题是当我单击该微调器时,文本颜色也是白色的,其背景微调器也是白色的..因此文本不可见..我希望微调器的所有项目都应该是黑色的..我有一些线程但是通过那个只有选定的项目显示黑色...... 需要你的 hlp...thnx 提前..
【问题讨论】:
标签: android
我是安卓新手..所以需要一些帮助.. 我有一个带有白色背景的 xml 页面..其中有一个微调器..解析后值填充在该微调器中..但问题是当我单击该微调器时,文本颜色也是白色的,其背景微调器也是白色的..因此文本不可见..我希望微调器的所有项目都应该是黑色的..我有一些线程但是通过那个只有选定的项目显示黑色...... 需要你的 hlp...thnx 提前..
【问题讨论】:
标签: android
你一定已经实现了spinner的onItemSelected。 像这样:
public class YourActivity_Name extends Activity implements
AdapterView.OnItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
spinner = (Spinner) findViewById(R.id.Spinner1);
spinner.setOnItemSelectedListener(this);
}
public void onItemSelected(AdapterView<?> parent, View view, int pos,
long id) {
((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
}
更新:
那么你一定在 spinner 中设置了像这样的项目:
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(
context, android.R.layout.simple_spinner_item,
array_spinner);
adapter.setDropDownViewResource(R.layout.simple_selectable_list_item);
spinner.setAdapter(adapter);
simple_selectable_list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:textAppearance="?android:attr/textAppearanceListItem"
android:gravity="center_vertical"
android:background="?android:attr/listChoiceBackgroundIndicator"
android:paddingLeft="8dip"
android:textColor="#ff0000"
android:paddingRight="8dip"
/>
【讨论】:
将此布局添加到布局文件夹,
MyspinnerTextview.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
style="?android:attr/spinnerItemStyle"
android:layout_width="fill_parent"
android:textColor="#000"
android:layout_height="wrap_content"
android:gravity="center" />
在代码中,
spinner=(Spinner)getActivity().findViewById(R.id.district);
ArrayAdapter<String> DisAdapter = new ArrayAdapter<String>(
YourActivity.this, R.layout.MyspinnerTextview,
yourarray);
DisAdapter
.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(DisAdapter);
【讨论】: