2

我是android中的新手..所以需要一些帮助..我有一个带有白色背景的xml页面..里面有一个微调器..解析后值正在填充到该微调器中..但问题是当我点击在那个微调器上,文本颜色也是白色,该微调器的背景也是白色..因此文本不可见..我希望微调器的所有项目都应该是黑色..我有一些线程但是通过该唯一选定的项目显示黑色...需要您的 hlp...thnx 提前..

4

2 回答 2

6

您必须已经实现了微调器的 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
}


}

更新:

然后你必须在微调器中设置项目,如下所示:

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"

/>

于 2013-06-18T05:38:41.833 回答
0

将此布局添加到布局文件夹,

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);
于 2013-06-18T05:27:54.123 回答