Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
344 views
in Technique[技术] by (71.8m points)

android - How should I increase the spinner list item font size?

This is my spinner's code:

Spinner food = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> foodadapter = ArrayAdapter.createFromResource(
        this, R.array.item_array, android.R.layout.simple_spinner_item);
foodadapter.setDropDownViewResource(android.R.layout.simple_spinner_item);        
food.setAdapter(foodadapter);

This is a part of the layout file where I have created the spinner:

<Spinner
        android:id="@+id/spinner1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:layout_toRightOf="@+id/textView1" />

This is the item_array:

<resources>
    <string name="item_picker">Select an iten</string>
    <string-array name="item_array">
        <item>Pizza</item>
        <item>Burger</item>
        <item>Sandwiches</item>
        <item>Bread</item>
        <item>Pastries</item>
        <item>Snackers</item>
    </string-array>
</resources>

Note: I do not want a simple_spinner_dropdown_item.

I just want to increase the size of the list items. How can I do that?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Save the below xml as spinner_layout.xml in layout folder

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
          android:id="@+id/spinnerTarget"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textColor="#000000"
          android:textSize="13sp"
/>

change the textSize which you want. and use the below adapter code to fill it.

Spinner food = (Spinner) findViewById(R.id.spinner1);
ArrayAdapter<CharSequence> foodadapter = ArrayAdapter.createFromResource(
            this, R.array.item_array, R.layout.spinner_layout);
foodadapter.setDropDownViewResource(R.layout.spinner_layout);
food.setAdapter(foodadapter);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...