我正在为我的应用程序使用Caldroid库,我遇到了一个问题。
我只希望当前月份的日期显示在我的日历上。
我查看了Caldroid文档,但找不到任何内容。
我知道我可以设置日历的最大日期,但我找不到任何设置每月最大/分钟的内容。
答案 0 :(得分:5)
希望这会帮助你:)
我有同样的问题并做了类似的事情。
在drawable中创建新的选择器,例如 calendar_cell_text_color.xml 。在这个文件中你就像这样。
<!-- Caldroid days from prev and next month -->
<item android:color="@color/white" caldroid:state_date_prev_next_month="true"/>
<!-- Caldroid days from current month -->
<item android:color="@color/black" />
现在,你必须改变CaldroidDefaultCell的风格。
在文件style.xml中添加以下行。
<!-- My Caldroid theme. -->
<style name="MyCaldroid" parent="CaldroidDefault">
<!--If you use compact view in Caldroid -->
<item name="styleCaldroidNormalCell">@style/CaldroidCell</item>
<!-- If you use square (default) view in Caldroid-->
<item name="styleCaldroidSquareCell">@style/CaldroidCell</item>
</style>
<style name="CaldroidCell" parent="CaldroidDefaultCell">
<item name="android:textColor">@drawable/calendar_cell_text_color</item>
</style>
现在你需要在启动caldroid后添加一行来使用你的主题。
caldroidFragment = new CaldroidFragment();
caldroidFragment.setThemeResource(R.style.MyCaldroid);
现在其他月份的日期将不可见,但您仍然可以点击它们。我现在正在努力弄清楚如何禁用它们。
编辑:
如果要禁用日期
//date argument is current month visible on screen
public void disablePrevNextMonthDay(Date date){
disableDates.setTime(date); // disableDates is a Calendar object
disableDates.set(Calendar.DAY_OF_MONTH, 1); // 1st day of current month
caldroidFragment.setMinDate(disableDates.getTime());
int maxDay = disableDates.getActualMaximum(Calendar.DAY_OF_MONTH);
disableDates.set(Calendar.DAY_OF_MONTH, maxDay);
caldroidFragment.setMaxDate(disableDates.getTime()); //last day of current month
}
你在caldroid的onChangeMonth()方法中调用这个方法。
如果您在类似 calendar_cell_text_color.xml 的文件中添加选择器 state_date_disabled ,并将背景设置为白色,就像上一个带有文字颜色的示例一样,您将拥有不可见的非点击日期。