Change text color of selected item in spinner

后端 未结 14 1547
情深已故
情深已故 2020-11-29 06:17

How can I change the font color of the selected item in a spinner?

I am able to change the background color of the selected item, the color of the dropdown item etc,

14条回答
  •  忘掉有多难
    2020-11-29 07:02

    If your spinner is using an ArrayAdapter, you can simply pass a custom layout for your spinner items. That layout can be a simple textView but with the android:textColor attribute.

    MainActivity.java onCreate()

    adapter = new ArrayAdapter<>(this, R.layout.spinner_custom_textcolor, data);
    spinner.setAdapter(adapter);
    

    spinner_custom_textcolor.xml

    
    

    *Everything from the above layout except for android:textColor is a direct copy from android.R.layout.simple_spinner_item

提交回复
热议问题