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

后端 未结 7 628
天命终不由人
天命终不由人 2020-12-08 01:10

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 incre

7条回答
  •  执念已碎
    2020-12-08 01:38

    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.

    
    

提交回复
热议问题