Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to color and alignment spinner item on android?

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

like image 328
mrmamon Avatar asked Mar 22 '10 12:03

mrmamon


1 Answers

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" />
like image 153
Pentium10 Avatar answered Oct 25 '22 07:10

Pentium10