8

I'm try to change text color and align item in spinner to center of it how can I do this

here is my code

    String[] li={"1","2","3"};
final Spinner combo = (Spinner)findViewById(R.id.widget30);
ArrayAdapter<String> a = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, li);
combo.setAdapter(a);

Thanks

Nikhil
  • 16,194
  • 20
  • 64
  • 81
mrmamon
  • 151
  • 1
  • 3
  • 7

1 Answers1

20

Use a custom view for that, and specify by calling:

a.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

Note that you have to use your own view here: R.id.my_simple_spinner_dropdown_item

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@android:id/text1"
    style="?android:attr/spinnerItemStyle"
    android:singleLine="true"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:ellipsize="marquee" />
Pentium10
  • 204,586
  • 122
  • 423
  • 502
  • Very nice... worked for me. Seems odd to be styling a Spinner with a TextView, but it certainly works. Do Spinners somehow inherit text colors without styling them this way? On emulator, I had different behavior than on phone. Phone gave me white text on white background... obviously a problem. This technique allows me to force visibility. – Mike L Dec 21 '10 at 22:08
  • 1
    There is a big downside to this solution. In order to set items RTL you need to give it a width of fill_parent or match_parent. How align items RTL when using wrap_content for TextView? since we usually want the width of our spinner be equal to the largest item width. – Alireza Ahmadi Oct 27 '15 at 10:36