Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - can I increase the textSize for the NumberPicker widget?

We got a NumberPicker widget in 3.0, but it seems that the textSize for this widget can't be modified. Am I missing something or is this the case? I'd really like to increase the font size, it's quite small with the default value. But I can't see a textSize property for it.

like image 651
Zsombor Erdődy-Nagy Avatar asked Aug 05 '11 15:08

Zsombor Erdődy-Nagy


1 Answers

I was able to accomplish this by extending the default NumberPicker. Not ideal, but it works.

public class NumberPicker extends android.widget.NumberPicker {     public NumberPicker(Context context, AttributeSet attrs) {      super(context, attrs);    }     @Override    public void addView(View child) {      super.addView(child);      updateView(child);    }     @Override    public void addView(View child, int index, android.view.ViewGroup.LayoutParams params) {      super.addView(child, index, params);      updateView(child);    }     @Override    public void addView(View child, android.view.ViewGroup.LayoutParams params) {      super.addView(child, params);      updateView(child);    }     private void updateView(View view) {      if(view instanceof EditText){        ((EditText) view).setTextSize(25);        ((EditText) view).setTextColor(Color.parseColor("#333333"));      }    }   } 

Then just reference this class in your layout xml.

<com.yourpackage.NumberPicker         android:id="@+id/number_picker"         android:layout_width="43dp"         android:layout_height="wrap_content" /> 
like image 75
aheuermann Avatar answered Oct 14 '22 08:10

aheuermann