How to change spinner text size and text color?
Make a custom XML file for your spinner item.
spinner_item.xml:
Give your customized color and size to text in this file.
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:gravity="left"
android:textColor="#FF0000"
android:padding="5dip"
/>
Now use this file to show your spinner items like:
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, R.layout.spinner_item,list);
You don't need to set the drop down resource. It will take spinner_item.xml
only to show your items in spinner.
change Spinner text color
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"/>
How to change text color in spinner without using textview
I got solution for this, Create a new xml "spinner_style.xml"
<?xml version="1.0" encoding="UTF-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:textColor="@color/Black" />
And fix this layout as your spinner style in your activity:
ArrayAdapter<String > gender_adapter = new ArrayAdapter<String> (getActivity(), R.layout.spinner_style,gender_spinner );
How to change spinner text color
Here You have to set your spinner_item.xml in your array adapter. Add this piece of code in your .java file
Spinner yourSpinner;
ArrayAdapter<String> yourAdapter;
yourSpinner= (Spinner) findViewById(R.id.yourSpinnerID);
yourSpinner.setAdapter(yourAdapter);
yourAdapter= new ArrayAdapter<String>(this, R.layout.spinner_item, value);
//here value is your items in spinner..
Spinner text size does not change?
What you should do for custom Spinners is create a single XML that will act as your template for the string in the Spinner, like so:
<?xml version="1.0" encoding="UTF-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/standard_spinner_format"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="@dimen/pt"
android:textColor="@android:color/holo_blue_dark"/>
Then when you create your Spinner adapter in java do the following:
ArrayAdapter<CharSequence> typeAdapter = ArrayAdapter.createFromResource(getActivity(),
R.array.my_spinner_array, R.layout.custom_xml_spinner_layout); //change the last argument here to your xml above.
typeAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Change text color of selected item in spinner
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.
how to change spinner text size and color, not in the popup window?
Use the below adapter constructor for customizing spinner in the way
you required.
spinnerAdapter = new ArrayAdapter(this, R.layout.row_spinner
/* The resource ID for a layout file containing a layout to use when
instantiating views. */ ,android.R.id.text1, array);
And you can set the layout resource defining the drop down views using
spinnerAdapter.setDropDownViewResource(R.layout.layout_spinner);
Sample layouts
row_spinner
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ellipsize="marquee"
android:gravity="center"
android:singleLine="true"
android:textColor="@color/colorBlack"
android:textColorHint="@color/colorBlack"
android:textSize="@dimen/text_size_l"/>
layout_spinner
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@android:id/text1"
style="?android:attr/spinnerDropDownItemStyle"
android:layout_width="match_parent"
android:layout_height="@dimen/margin_padding_width_height_6"
android:ellipsize="end"
android:gravity="center"
android:singleLine="true"
android:textColor="@color/colorBlackLight"
android:textSize="@dimen/text_size_l"/>
Related Topics
Onitemclicklistener Not Working in Listview
Gridlayout (Not Gridview) How to Stretch All Children Evenly
How to Programmatically Tell If a Bluetooth Device Is Connected
How to Programmatically Add Views to Views
How to Add an Array or Object to Sharedpreferences on Android
Eclipse Giving Error, Missing R.Java File After Recent Update
Is Asynctask Really Conceptually Flawed or Am I Just Missing Something
How to Hide Soft Keyboard on Android After Clicking Outside Edittext
Animate Change of View Background Color on Android
How to Add a Border to the Top and Bottom of an Android View
Adb Android Device Unauthorized
How to Develop a Soft Keyboard For Android