xml文件:
<CalendarView
android:id="@+id/cal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusedMonthDateColor="#13c016"
android:weekSeparatorLineColor="#000000"
>
</CalendarView>
avtivity:(下面是在fragment中的代码,一样的)
public class DiscoveryFragment extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View view = View.inflate(getActivity(), R.layout.fragment_discovery, null);
CalendarView calendarView=(CalendarView)view.findViewById(R.id.cal);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int year, int month, int dayOfMonth) {
if(dayOfMonth){
Toast.makeText(getContext(),"1",Toast.LENGTH_SHORT).show();
}
}
});
return view;
}
}