我是Android开发新手并开始开发预订应用程序。有一个日历视图,我想禁用该日历中的预订日期。我发现Android默认日历中没有禁用功能。那么请你帮我找一个可以禁用特定日期的自定义日历视图。我需要资源或库。谢谢!
答案 0 :(得分:3)
在布局XML中包含CalendarPickerView。
<com.squareup.timessquare.CalendarPickerView
android:id="@+id/calendar_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
在活动/对话框的onCreate或片段的onCreateView中,使用一系列有效日期和当前选定的日期初始化视图。
Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
CalendarPickerView calendar = (CalendarPickerView) findViewById(R.id.calendar_view);
Date today = new Date();
calendar.init(today, nextYear.getTime()).withSelectedDate(today);
github link- https://github.com/square/android-times-square
答案 1 :(得分:0)
i have faced the same problem using custom calendar ,
i just overridden the function of adapter
@Override
public boolean isEnabled(int position) {
if(mySet.contains(position))
return true;
else
return false;
}
then i call the function int the adapter view
isEnabled(position);
befoer that tale Hashset and add the position which is displaying the calanderview
// mysetSize=set.size();
//isEnabled(Integer.parseInt(gridvalue));
Log.d(dayView.getTag()+"------1-------"+gridvalue,"-------"+position);
} else if ((Integer.parseInt(gridvalue) < 7) && (position > 28)) {
dayView.setTextColor(Color.WHITE);
dayView.setClickable(false);
dayView.setFocusable(false);
Log.d("-------mySet------","-------"+mySet);
Log.d(mysetSize+"-------28------"+gridvalue,"-------"+position);
set.add(position);
} else {
// setting curent month's days in blue color.
dayView.setTextColor(Color.DKGRAY);
Log.d(dayView.getTag()+"-------current display post------","-------"+position);
mySet.add(position);
}