Change text color of selected item in spinner

后端 未结 14 1524
情深已故
情深已故 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:07

    drawable/mybg:

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android">
        <item android:state_activated="true">
            <color android:color="@color/black" />
        </item>
    </layer-list>
    

    This will change the selected item color in the popup.

    0 讨论(0)
  • 2020-11-29 07:10

    Define OnItemSelectedListener like this:

      private AdapterView.OnItemSelectedListener listener = new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                ((TextView) parent.getChildAt(0)).setTextColor(0x00000000);
            }
    
            @Override
            public void onNothingSelected(AdapterView<?> parent) {
    
            }
        };
    

    and then Set OnItemSelectedListener to spinner like this:

    spinner.setOnItemSelectedListener(listener);
    
    0 讨论(0)
提交回复
热议问题