Android only month and year collector in material design

Im working on an application that should enter a credit card expiration date, but andorid 5.0+ date time picker has only options for choosing a date with days. Is there any library because I can not find it. I also did not find anything in the material development guide regarding this.

thanks

+4
source share
2 answers

After you made a modified date picker called Simple Date picker ... used a code similar to Date Picker to show the month and year. You can also provide your own theme in SimpleDatePickerDialog.

. https://github.com/resengupta/Month-Year-Date-Picker

+1

,

        Field f[] = picker.getClass().getDeclaredFields();
    for (Field field : f) {
        if (field.getName().equals("mDayPicker")) {
            field.setAccessible(true);
            Object dayPicker = new Object();
            dayPicker = field.get(picker);
            ((View) dayPicker).setVisibility(View.GONE);
        }
    }
} 
catch (SecurityException e) {
    Log.d("ERROR", e.getMessage());
} 
catch (IllegalArgumentException e) {
    Log.d("ERROR", e.getMessage());
} 
catch (IllegalAccessException e) {
    Log.d("ERROR", e.getMessage());
}

DatePicker dpDate = (DatePicker) findViewById(R.id.dpDate);

// Initialize Date Picker
int year    = dpDate.getYear();
int month   = dpDate.getMonth();
int day     = dpDate.getDayOfMonth();
dpDate.init(year, month, day, this);

if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
        {
            int daySpinnerId = Resources.getSystem().getIdentifier("day", "id", "android");
            if (daySpinnerId != 0) 
            {
                View daySpinner = dpDate.findViewById(daySpinnerId);
                if (daySpinner != null) 
                {
                    daySpinner.setVisibility(View.GONE);
                }
            }
        }

        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
        {
            int monthSpinnerId = Resources.getSystem().getIdentifier("month", "id", "android");
            if (monthSpinnerId != 0) 
            {
                View monthSpinner = dpDate.findViewById(monthSpinnerId);
                if (monthSpinner != null) 
                {
                    monthSpinner.setVisibility(View.GONE);
                }
            }
        }

        if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
        {
            int yearSpinnerId = Resources.getSystem().getIdentifier("year", "id", "android");
            if (yearSpinnerId != 0) 
            {
                View yearSpinner = dpDate.findViewById(yearSpinnerId);
                if (yearSpinner != null) 
                {
                    yearSpinner.setVisibility(View.GONE);
                }
            }
        }

, DatePicker Android 5.0+ Lollipop

0

Source: https://habr.com/ru/post/1607998/


All Articles