Ninja
Ninja

Reputation: 2568

How to reduce the font size in NumberPicker

All, I'm customizing a city picker, which uses three numberPicker inside,like this: enter image description here

Its a Chinese province-city-area picker.

The code:

String[] areas = get_from_somewhere();
areaPicker.setDisplayedValues(areas);

I want to reduce the font size,any advice?

Solution: Refer to this

Upvotes: 5

Views: 12644

Answers (3)

Jakub S.
Jakub S.

Reputation: 6080

Based on John Starbird answer.

You add style.

<style name="NumberPickerText">
    <item name="android:textSize">11sp</item>
</style> 

Add style to your Number Picker in XML.

android:theme="@style/NumberPickerText"

Upvotes: 4

MysticMagicϡ
MysticMagicϡ

Reputation: 28823

You can extend the default NumberPicker in your Custom class CustomNumberPicker for this:

public class CustomNumberPicker extends NumberPicker {

    public NumberPicker(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public void addView(View child) {
        super.addView(child);
        if(child instanceof EditText) {
            ((EditText) child).setTextSize(25);
        }
    }
}

Now replace your current NumberPicker in xml with CustomNumberPicker:

<com.pkg.name.CustomNumberPicker
    android:id="@+id/number_picker"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

Upvotes: 7

repkap11
repkap11

Reputation: 797

Although technically not changing the font size, the size of the text can be changed by changing the scale of the entire NumberPicker View.

<NumberPicker
    android:id="@+id/number_picker"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleX=".7"
    android:scaleY=".7"/>

Upvotes: 7

Related Questions