How to color and alignment spinner item on android

2019-01-09 11:22发布

问题:

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

回答1:

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" />