我试图自定义Android CalendarView,但我根本无法弄清楚如何做到这一点。我想要的例子是,日历仅显示接下来的7天,如果你在接下来的7天刷卡等等......这可能吗?我认为可以通过设置min和maxDate()来设置整个日历然后你不能刷...
我得到了这个:
import android.graphics.Color;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.CalendarView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
CalendarView simpleCalendarView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
simpleCalendarView = (CalendarView) findViewById(R.id.simpleCalendarView); // get the reference of CalendarView
simpleCalendarView.setFocusedMonthDateColor(Color.RED); // set the red color for the dates of focused month
simpleCalendarView.setUnfocusedMonthDateColor(Color.BLUE); // set the yellow color for the dates of an unfocused month
simpleCalendarView.setSelectedWeekBackgroundColor(Color.RED); // red color for the selected week's background
simpleCalendarView.setWeekSeparatorLineColor(Color.GREEN); // green color for the week separator line
// perform setOnDateChangeListener event on CalendarView
simpleCalendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year, int month, int dayOfMonth) {
// display the selected date by using a toast
Toast.makeText(getApplicationContext(), dayOfMonth + "/" + month + "/" + year, Toast.LENGTH_LONG).show();
}
});
}
现在我可以在那段代码中做到这一点,还是我必须完全自己“绘制”日历或如何? :S
请求帮助
答案 0 :(得分:1)
我知道现在已经很晚了,但您可以将library MaterialCalendarView用于此目的。
只需将其添加到您的布局并将app:mcv_calendarMode="week"
设置为属性即可。这就是它 - 只显示当前的一周,你可以刷几周。