如何在 Android CalendarView 上仅显示特定月份?
How to show only a specific month on Android CalendarView?
我想在 CardView 上显示特定的月份 没有 NEXT 和 PREVIOUS 箭头来导航日历。如果我想显示 2010 年 2 月,用户必须只看到 2010 年 2 月。他们不能去下个月或上个月。
我按照 Stack Overflow 的回答来显示特定的月份,但它对我不起作用。它始终显示我的案例的当前日期和月份。我不确定是否可以禁用 NEXT-PREVIOUS 导航。
我的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="megaminds.dailyeditorialword.Fragments.CalendarViewFragment">
<CalendarView
android:id="@+id/calendarViewT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:firstDayOfWeek="7">
</CalendarView>
onCreateView
我的片段 class:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_calendar_view, container, false);
int year = 2010, month = 2, day = 1;
CalendarView calendarView = (CalendarView) view.findViewById(R.id.calendarViewT);
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day); //want to show full month of February 2010
calendarView.setMinDate(calendar.getTimeInMillis());
return view;
}
如何在没有 next-previous 导航的情况下只显示 2 月份?
Calendar febFirst=Calendar.getInstance();
febFirst.set(2017, 1, 1, 0, 0, 0);
calendar.setMinDate(febFirst.getTimeInMillis());
Calendar febLast=Calendar.getInstance();
febLast.set(2017, 2, 0, 0, 0, 0);
calendar.setMaxDate(febLast.getTimeInMillis());
calendar.setDate(febFirst.getTimeInMillis());
其中 calendar
是 CalendarView
。
int day = 16;
int month =8;
int year =2017;
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day);
long milliTime = calendar.getTimeInMillis();
mCalendarView.setDate (milliTime, true, true);
这里的 mCalendarView 是 Android 日历视图
我想在 CardView 上显示特定的月份 没有 NEXT 和 PREVIOUS 箭头来导航日历。如果我想显示 2010 年 2 月,用户必须只看到 2010 年 2 月。他们不能去下个月或上个月。
我按照
我的XML:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="megaminds.dailyeditorialword.Fragments.CalendarViewFragment">
<CalendarView
android:id="@+id/calendarViewT"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:firstDayOfWeek="7">
</CalendarView>
onCreateView
我的片段 class:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_calendar_view, container, false);
int year = 2010, month = 2, day = 1;
CalendarView calendarView = (CalendarView) view.findViewById(R.id.calendarViewT);
Calendar calendar = Calendar.getInstance();
calendar.set(year, month, day); //want to show full month of February 2010
calendarView.setMinDate(calendar.getTimeInMillis());
return view;
}
如何在没有 next-previous 导航的情况下只显示 2 月份?
Calendar febFirst=Calendar.getInstance();
febFirst.set(2017, 1, 1, 0, 0, 0);
calendar.setMinDate(febFirst.getTimeInMillis());
Calendar febLast=Calendar.getInstance();
febLast.set(2017, 2, 0, 0, 0, 0);
calendar.setMaxDate(febLast.getTimeInMillis());
calendar.setDate(febFirst.getTimeInMillis());
其中 calendar
是 CalendarView
。
int day = 16;
int month =8;
int year =2017;
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.YEAR, year);
calendar.set(Calendar.MONTH, month); calendar.set(Calendar.DAY_OF_MONTH, day);
long milliTime = calendar.getTimeInMillis();
mCalendarView.setDate (milliTime, true, true);
这里的 mCalendarView 是 Android 日历视图