How can we set a drawable background to scrolled position in Number Picker in Native Android

145 views Asked by At

I'm implementing a Number Picker for my native Android Application. I have a requirement to show the scrolled position in number Picker to be selected with a drawable layout. How can I implement that in Number Picker?

layoutFile:

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/seekBar"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="center">


    <NumberPicker
        android:id="@+id/num_picker"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:background="@drawable/picker_background">

    </NumberPicker>


</RelativeLayout>

Activity Code:

public class MainActivity extends AppCompatActivity {

    private NumberPicker numberPicker;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initViews();
    }

    private void initViews(){

        numberPicker = findViewById(R.id.num_picker);


        numberPicker.setMinValue(1);
        numberPicker.setMaxValue(9);

    }

}
0

There are 0 answers