Change text color of selected item in spinner

android change spinner text color programmatically
change background color of the selected item in android spinner
how to change default spinner text color in android
spinner text color android
android spinner text color is white
spinner items text color
spinner color
spinner hint color android

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, but not the text color of selected item... how can I do that?

my code is: this is spinner i am using--:

<Spinner
                android:id="@+id/spinner1"
                android:layout_width="wrap_content"
                android:layout_height="32dip"
                android:background="@drawable/mybg"
                android:divider="@drawable/list_divider"
                android:drawSelectorOnTop="true"
                android:popupBackground="#D3D5D3"
                android:prompt="@string/activityy_prompt" 
                />

this is mybg.xml

<!-- <item android:drawable="@drawable/blue" android:state_pressed="false"/> -->
<!-- <item android:drawable="@drawable/back11"/> -->

<item android:drawable="@drawable/greenyellow1" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/greenyellow1" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/greenyellow1" android:state_focused="false" android:state_pressed="true"/>
<item android:drawable="@drawable/greenyellow1" android:state_selected="true"/>
<item android:drawable="@drawable/back11"/>

using these i am not able to change the text color of selecetd item...

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.

android, When working with android spinner, there might be a case when we need to change the text color of the selected item of a spinner to give our users the sense of. When working with android spinner, there might be a case when we need to change the text color of the selected item of a spinner to give our users the sense of which item is currently selected. To learn how to change the text color of selected spinner item in android, we will create a simple code to illustrate this features. activity_layout.xml

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

How to Change Text Color of Selected Spinner Item in Android, Here's an example showing how to change the text and the color of the selected item. spinner.setOnItemSelectedListener(new AdapterView. Now I want to change the text color and text size of spinner data. I have used following XML lines to my spinner tag on my XML file, but it is not working. android:textColor="@android:color/white" android:textSize="11dp" How can I change the text color and text size of my spinner?

try implementing onItemSelected in your OnItemSelectedListener for change the text color of spinner selected item

public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) { 
    int index = adapterView.getSelectedItemPosition();
    ((TextView) spinner.getSelectedView()).setTextColor(getResources().getColor(R.color.Blue)); //<----

Android - How to set the text color of a closed spinner, MainActivity" android:background="#effbe4" > <Spinner android:layout_height​="wrap_content" android:textColor="#ff0c35" android:padding="10dp" /> How to set ListView item/row height in Android · How to scroll to the  I have a spinner where in certain conditions some options should not be selectable. I have the code to make items not selectable but it does not grey out text color to specify that the item is not selectable. How would I change the text color of the items in the spinner that should be disabled? Here is the code:

You can change the selected text color by adding OnItemSelectedListener to the spinner

qtySpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        ((TextView) view).setTextColor(Color.BLACK); //Change selected text color
    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }
});

Change color of the Spinner Android, If you want the text color to change in the selected item only, then this can be a possible workaround. It worked for me and should work for you as well. View more  Podcast #128: We chat with Kent C Dodds about why he loves React and discuss what life was like in the dark days before Git. Listen now.

using selector as text color .

create color_selector.xml in drawable like

<?xml version="1.0" encoding="utf-8"?>
 <selector xmlns:android="http://schemas.android.com/apk/res/android">
     <item android:state_pressed="true"
           android:color="#000000" /> <!-- pressed -->
     <item android:state_focused="true"
           android:color="#000000" /> <!-- focused -->
     <item android:color="#FFFFFF" /> <!-- default -->
 </selector>

and in textview

<TextView 
   android:textColor="@drawable/color_selector"/>

How to change Spinner text color in Android, Text Color Changes to White when select item from searchable spinner - android. On selection of 1st Spinner item, I am Changing the adapter of the 2nd  And then change your declaration of the spinner to use the R.layout.spinner_item: ArrayAdapter adapter = ArrayAdapter.createFromResource(this, R.array.planets_array, R.layout.spinner_item); spinner.setAdapter(adapter); This is the result: If you want to customize the dropdown list items you will need to create a new layout file. Let’s call it

android How to change spinner text size and text color?, To achieve spinner text color change in android, we will change the color of each spinner item text in the drop down resource layout file. "Select") at first  Spinner itself cannot gives us any method or attribute to change text color but when we create spinner using textview and string array then we can set text view color and that will become the whole spinner texts color. So here is the complete step by step tutorial for Change spinner text color in android programmatically.

Text Color Changes to White when select item from searchable , We will also see how to change the text color and size of dropdown text and change color size of selected item in dropdown of spinner. For this whole purpose we  Read about Android Spinner Text Color Size Programmatically tutorial example here. In this tutorial, you will learn to change the text color and size of android spinner Programmatically. You will also learn to change the text color and size of selected item of spinner.

Android spinner text color, If you want to customize or change spinner text color, you can achieve it in one of the following ways listed below. Change Spinner Text Color in XML layout. To achieve spinner text color change in android, we will change the color of each spinner item text in the drop down resource layout file. activity_spinner_text_color.xml

Comments
  • use this link , it will help stackoverflow.com/questions/7584158/…
  • feed us the code which you tried.No coin No Call
  • @user1283633 i follow this link and able to change background color only.... not able to change text color...
  • change android:drawable="@color/red"
  • Thx... its working .. earlier it was not working but now its working may be because i add few line in manifest file like.... android:configChanges="orientation|keyboardHidden|screenLayout|screenSize"
  • This might cause a little lag on setting the default selection's color. See my answer here which fixes that problem: stackoverflow.com/questions/9476665/…
  • This must be the answer accepted.
  • Excellent! Add this to change the text size while you are at it: ((TextView) view).setTextSize(30f);
  • Works really well programmatically! Thank you!
  • Unfortunately there appears to be a lag where you can see the color switch from the default to the new one.
  • weird. here nothing related to background, all you need to do is use android:textColor=""@drawable/color_selector" with view contains text (spinner/textView) .
  • is there property textcolor for spinner??
  • hopefully. else you will need to use textview along with spinner for this approach.
  • This is much elegant solution.
  • i use it , and when run app , app crash