Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/196.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用日历视图禁用所有其他日期,然后禁用当前日期_Android_Android Studio_Date_Calendar_Disable - Fatal编程技术网

Android 如何使用日历视图禁用所有其他日期,然后禁用当前日期

Android 如何使用日历视图禁用所有其他日期,然后禁用当前日期,android,android-studio,date,calendar,disable,Android,Android Studio,Date,Calendar,Disable,我想使用日历视图禁用所有日期。我已经找到了一个代码,应该能够做到这一点,但有几个红色的字,我认为这是由于一个包丢失的事实,但我不知道哪一个和如何得到它。我应该导入什么才能让它工作?它显示DayDecorator、docorate和DayView上的错误 我正在使用这个代码: enter code here private class DaysDecorator implements DayDecorator { @Override public void dec

我想使用日历视图禁用所有日期。我已经找到了一个代码,应该能够做到这一点,但有几个红色的字,我认为这是由于一个包丢失的事实,但我不知道哪一个和如何得到它。我应该导入什么才能让它工作?它显示DayDecorator、docorate和DayView上的错误

我正在使用这个代码:

enter code here

private class DaysDecorator implements DayDecorator {
        @Override
        public void decorate(DayView dayView) {
            if(!isPastDay(dayView.getDate())){
                dayView.setBackgroundColor(getResources().getColor(R.color.disable_color));
            }
        }
    }
    private boolean isPastDay(Date date) {
        Calendar c = Calendar.getInstance();

        // set the calendar to start of today
        c.set(Calendar.HOUR_OF_DAY, 0);
        c.set(Calendar.MINUTE, 0);
        c.set(Calendar.SECOND, 0);
        c.set(Calendar.MILLISECOND, 0);

        // and get that as a Date
        Date today = c.getTime();

        // test your condition, if Date specified is before today
        if (date.before(today)) {
            return true;
        }
        return false;
    }

我很确定那些红色的单词意味着找不到该类,您需要导入它。如果您使用的是AndroidStudio Ctrl+Space,则这些单词会显示是否可以导入任何类。例如
导入android.view.view
;如果您不使用androidx,则使用Daydecontor