Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

android - Spinner text size does not change?

I could not change spinner's textsize or colour with the code below:

<Spinner 
    android:id="@+id/spinner1"
    style="@style/submitspinner"
    android:layout_weight="2"
    android:entries="@array/a_code"
    android:prompt="@string/p_code" />

style:

<style name="submitspinner" parent="@android:TextAppearance.Widget.TextView.SpinnerItem">
    <item name="android:layout_width">wrap_content</item>
    <item name="android:layout_height">match_parent</item>
    <item name="android:layout_margin">10sp</item> 
    <item name="android:textColor">@android:color/holo_blue_dark</item>
    <item name="android:textSize">@dimen/pt</item> 
</style>

It looks same, how can I increase textsize and change colour of the spinner?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

Via XML Only

Just to help others in case they are statically setting their Spinner entries in XML.

The above answers work if you're creating your Spinner via code but if you're setting your Spinner entries via XML, i.e. using android:entries, then you can adjust the text size and other attributes with the following two theme settings:

In your res/values/styles.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <style name="AppBaseTheme" parent="android:Theme.Holo">
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">

        <!-- For the resting Spinner style -->
        <item name="android:spinnerItemStyle">
            @style/spinnerItemStyle
        </item> 

        <!-- For each individual Spinner list item once clicked on -->
        <item name="android:spinnerDropDownItemStyle">
            @style/spinnerDropDownItemStyle
        </item>

    </style>

    <style name="spinnerItemStyle">
        <item name="android:padding">10dp</item>
        <item name="android:textSize">20sp</item>
        <item name="android:textColor">#FFFFFF</item>
    </style>

    <style name="spinnerDropDownItemStyle">
        <item name="android:padding">20dp</item>
        <item name="android:textSize">30sp</item>
        <item name="android:textColor">#FFFFFF</item>
    </style>

</resources>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...