skip to Main Content

I’m writing an android tv app with lean-back and I want to use android standard date picker and I want to make this like this pic
(eg: Made year part bigger when the user is selecting year and so on)

How can I achieve this?

enter image description here

2

Answers


  1. Chosen as BEST ANSWER

    Use three different NumberPicker and write some custom logic for day, month and year.


  2. You cannot use the standard date picker in Android TV apps because it was not designed for navigation using D-Pad. However, you can create your own widgets for day, month and year selection. You can simply use VerticalGridView to create them. For instance, you can do something similar to this for days:

    <androidx.leanback.widget.VerticalGridView
        android:id="@+id/vgv_days"
        android:background="@color/transparent"
        android:layout_marginEnd="10dp"
        android:layout_width="40dp"
        android:layout_height="35dp" />
    

    customArrayObjectAdapterDays = new CustomArrayObjectAdapter(new DatePartPresenter(getContext()));
    for (int i = 1; i < 31; i++) {
        customArrayObjectAdapterDays.add(i);
    }
    

    vgvDays = (VerticalGridView) view.findViewById(R.id.vgv_days);
    vgvDays.setNumColumns(1);
    vgvDays.setAdapter(new ItemBridgeAdapter(customArrayObjectAdapterDays));
    

    You also have to set the number of days (28, 29, 30, 31) depending on the year and selected month.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search