Android - 微调文本颜色更改不起作用

时间:2014-01-11 19:45:33

标签: android spinner android-arrayadapter android-spinner textcolor

我想更改我的微调器的文本颜色(我希望选择的值为白色)。

我在这个论坛上对这个话题感兴趣,但它对我没有帮助。我为我的微调器(spin.xml)创建了布局xml文件。这就是我所拥有的:

spin.xml:

  <?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="fill_parent"
android:gravity="top"
android:singleLine="true"
android:textColor="#ffffff" />

我的onCreate()中的数组适配器:

 spinner = (Spinner) findViewById(R.id.shift);

    // Create an ArrayAdapter using the string array and a default spinner layout
    ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
            R.array.shiftarray, R.layout.spin);
    // Specify the layout to use when the list of choices appears
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    // Apply the adapter to the spinner
    spinner.setAdapter(adapter);

    spinner.setOnItemSelectedListener(new OnItemSelectedListener(){



        public void onItemSelected(AdapterView<?> arg0, View view, int pos, long id) {

            selected = spinner.getSelectedItem().toString();
            ((TextView) spinner.getChildAt(0)).setTextColor(1);
            Log.e("SELECT", selected);
        }

        public void onNothingSelected(AdapterView parent) {
            // Do nothing.
        }
    });

我该怎么做才能让它运作起来? 比你。 :)

1 个答案:

答案 0 :(得分:2)

简单有效......

 private OnItemSelectedListener OnCatSpinnerCL = new AdapterView.OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int pos,
            long id) {

        ((TextView) parent.getChildAt(0)).setTextColor(Color.BLUE);
        ((TextView) parent.getChildAt(0)).setTextSize(5);



    }

    public void onNothingSelected(AdapterView<?> parent) {

    }
};