简体   繁体   中英

Setting text size of entries in a spinner (spinnerMode='Dialog')

In android studio, how can I change the text size of entries in a spinner in dialog mode that references a string-array. Can I change the text size in the string array, or can that be an xml attribute on the spinner itself?

Make a spinner_dropdown_item.xml:

<TextView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/text1"
    style="?android:attr/spinnerDropDownItemStyle"
    android:singleLine="true"
    android:layout_width="match_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:ellipsize="marquee"
    android:textColor="@color/black"
    android:textSize="17sp">
    </TextView>

And in your java code:

SpinnerArrayAdapter adapter = new SpinnerArrayAdapter(this, R.layout.spinner_dropdown_item, your_array);
        adapter.setDropDownViewResource(R.layout.spinner_dropdown_item);
        Spinner spinner = (Spinner)findViewById(R.id.spinner1);
        spinner.setAdapter(adapter);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM