【问题标题】:Android - spinner text color change does not workAndroid - 微调器文本颜色更改不起作用
【发布时间】:2014-01-12 04:05:34
【问题描述】:

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

我在这个论坛上对这个话题感到不满,但这对我没有帮助。我已经为我的微调器 (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.
        }
    });

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

【问题讨论】:

  • 你知道使用选择器吗?另外,我会制作自定义适配器并在 getView() 中执行此操作。

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


【解决方案1】:

简单有效...

 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) {

    }
};

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-07-02
    • 1970-01-01
    • 2011-08-15
    • 1970-01-01
    • 2013-08-21
    • 1970-01-01
    相关资源
    最近更新 更多