更改解析后出现的微调器项目的文本颜色

Kes*_*raj 2 android

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

cap*_*oid 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
}


}
Run Code Online (Sandbox Code Playgroud)

更新:

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

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);
Run Code Online (Sandbox Code Playgroud)

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"
Run Code Online (Sandbox Code Playgroud)

/>