Search code examples
androidxamarinxamarin.formsxamarin.androidandroid-spinner

change Spinner text color


I want to change the default text color in Spinner to any other color. But I have not find the solution yet. All I got a solution through TextView like How to change spinner text size and text color?
Is there any other way, direct way for Spinner?

Note: Please provide solution for Xamarin. Thank you.


Solution

  • Try like this only for selected item color change:

    spinnerObject.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        ((TextView)parentView.getChildAt(0)).setTextColor(Color.RED);
    }
    });
    

    Another way:

    <style name="spinnerTheme">
    <item name="android:textColor">@color/gray_dark</item>
    </style>
    
    <Spinner
    android:id="@+id/spinner"
    android:layout_width="match_parent"
    android:layout_height="50dp"
    android:theme="@style/spinnerTheme"/>