How to reduce font size in NumberPicker

That's it, I'm setting up a city picker that uses three numberPicker inside, like this: enter image description here

His choice in a Chinese provincial town.

The code:

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

I want to reduce the font size, any advice?

Solution : Refer to this question.

+5
source share
3 answers

You can extend the standard NumberPicker in your custom CustomNumberPicker class 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 the current NumberPicker with xml with CustomNumberPicker :

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

Although it’s technically not possible to change the font size, you can change the text size by zooming 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"/> 
+8
source

Based on John Starbird's answer.

You add style.

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

Add style to your numbering set in XML.

 android:theme="@style/NumberPickerText" 
+1
source

Source: https://habr.com/ru/post/1205261/


All Articles