androidnumberpicker

How to create custom number picker in android?


How can I implement custom number picker in android the same below image?

numberpicker

I have checked android arsenal library did not work any help will be appreciated.


Solution

  • Add this to your dependencies in build.gradle:

    implementation 'com.shawnlin:number-picker:2.4.12'

    Add the exact code to your .xml file:

    <com.shawnlin.numberpicker.NumberPicker
        android:id="@+id/number_picker"
        android:layout_width="50dp"
        android:layout_height="200dp"
        android:layout_centerInParent="true"
        android:dividerPadding="10dp"
        app:np_dividerColor="#03A9F4"
        app:np_dividerDistance="30dp"
        app:np_dividerThickness="5dp"
        app:np_dividerType="underline"
        app:np_height="180dp"
        app:np_itemSpacing="-10dp"
        app:np_max="59"
        app:np_min="0"
        app:np_selectedTextColor="#2196F3"
        app:np_textColor="#CB6A6A6A"
        app:np_textSize="20dp"
        app:np_selectedTextSize="20dp"
        app:np_value="3"
        app:np_width="64dp" />
    

    For more customization you can check this GitHub link.

    Design will look something like the image below:

    enter image description here