如何在Android中将项目文本颜色设置为Spinner的白色

N S*_*rma 0 android spinner android-spinner

我正在使用我正在使用的演示应用程序Spinner并且具有类似黑色的背景颜色,因此Spinner选择的项目颜色默认为黑色,因此它不可见.

我希望通过xml或更新样式将此颜色更改为白色,以便它可以在黑色中显示.

<Spinner
    android:id="@+id/countrySpinner"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="15dp"
    android:hint="@string/country" />
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

有什么办法吗?提前致谢.

NSo*_*uth 5

尝试在OnItemSelectedListener中处理此问题.我认为以下内容应该有效.它获取所选项目的视图,在其中查找TextView(Spinner视图具有id为text1的TextView子项),并设置其颜色.

mySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

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

            TextView tmpView = (TextView) mySpinner.getSelectedView().findViewById(android.R.id.text1);
            tmpView.setTextColor(Color.WHITE);
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // do stuff

        }
    });
Run Code Online (Sandbox Code Playgroud)