Android只有材料设计的月份和年份选择器

Dom*_*uta 5 android android-datepicker material-design

我正在开发需要输入信用卡到期日的应用程序,但是andorid 5.0+日期时间选择器只有选择日期和日期的选项.是否有任何图书馆,因为我找不到.我也没有找到关于此的材料设计指南.

谢谢

Ash*_*wal 0

请尝试这个

        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());
}
Run Code Online (Sandbox Code Playgroud)

你可以试试这个

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);
                }
            }
        }
Run Code Online (Sandbox Code Playgroud)

了解更多信息

在 Android 5.0+ Lollipop 中隐藏 DatePicker 中的日、月或年