我正在为我的应用程序使用Caldroid库,我遇到了一个问题.
我只希望当前月份的日期显示在我的日历上.
我查看了Caldroid文档,但找不到任何内容.
我知道我可以设置日历的最大日期,但我找不到任何设置每月最大/分钟的内容.
希望这会帮助你:)
我有同样的问题,并做了类似的事情.
在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" />
Run Code Online (Sandbox Code Playgroud)
现在,你必须改变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>
Run Code Online (Sandbox Code Playgroud)
在启动caldroid之后,你需要添加一行来使用你的主题.
caldroidFragment = new CaldroidFragment();
caldroidFragment.setThemeResource(R.style.MyCaldroid);
Run Code Online (Sandbox Code Playgroud)
现在,其他月份的日期将不可见,但您仍然可以点击它们.我现在正在努力弄清楚如何禁用它们.
编辑:
如果要禁用日期
//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
}
Run Code Online (Sandbox Code Playgroud)
你从caldroid的onChangeMonth()方法中调用这个方法.
如果您在类似于calendar_cell_text_color.xml的文件中添加选择器state_date_disabled并将背景设置为白色,就像上一个带有文本颜色的示例一样,您将拥有不可见的非点击日期.
| 归档时间: |
|
| 查看次数: |
2192 次 |
| 最近记录: |