Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change size of a numberpicker Android

I'm trying to decrease the size of an Android numberpicker, but already tried several things and I could not. I did not find a responsible attribute the change in size. Wanted to do the following:

enter image description here

Must decrease because I have to put the numberpicker on a screen with lots of information. Any help will be appreciated.

like image 253
Jefferson Avatar asked Jan 09 '23 23:01

Jefferson


2 Answers

I was facing a similar problem, I wanted to increase the text size of the NumberPicker but couldn't find a way to do it as part of the Widget. In my research I found the following solution:

<NumberPicker
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:scaleX="0.75"
    android:scaleY="0.75"/>

Think of scaleX and scaleY as a magnifying factor. Values < 1 will shrink the Widget, 1 will have no change, and > 1 will increase its size.

like image 146
Shah Avatar answered Jan 11 '23 11:01

Shah


Number Picker is quite not straight forword to modify or customize. Below is code which will adjust the NumberPicker height to 360dp actual values are considered match parent or wrap content in height will not be considered.

Text color,Text size,divider color can be changed as per style mentioned below

Height and style of number picker:

<NumberPicker
  android:id="@+id/np_month"
  android:layout_width="wrap_content"
  android:layout_height="360dp"
  android:theme="@style/AppTheme.Picker" />

Style:

  <style name="AppTheme.Picker" parent="Theme.AppCompat.Light.NoActionBar" >
        <item name="android:textColorPrimary">@android:color/white</item>
        <item name="android:textSize">40sp</item>
        <item name="colorControlNormal">@android:color/transparent</item>
    </style>
like image 45
Vinayak Avatar answered Jan 11 '23 11:01

Vinayak