Ben*_*Ben 3 java android gregorian-calendar calendarview
我创建了一个自定义 CalendarView,如下所示:
我希望过去的日子都有不同的颜色。
我的 XML 是:
<CalendarView
android:id="@+id/cv_Calendar"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:background="@drawable/cv_background"
android:dateTextAppearance="@style/CalenderViewDateCustomText"
android:theme="@style/CalenderViewCustom"
android:weekDayTextAppearance="@style/CalenderViewWeekCustomText"
app:layout_constraintTop_toBottomOf="@+id/tv_With" />
Run Code Online (Sandbox Code Playgroud)
我的风格是:
<style name="CalenderViewCustom" parent="Theme.AppCompat">
<item name="colorAccent">@color/colorLightGray</item>
<item name="colorPrimary">@color/colorLightPurple</item>
<item name="android:textColorPrimary">@color/colorGrayText</item>
</style>
<style name="CalenderViewDateCustomText" parent="android:TextAppearance.Holo.Small">
<item name="android:textColor">@color/colorLightPurple</item>
<item name="android:weekNumberColor">@color/colorLightPurple</item>
</style>
<style name="CalenderViewWeekCustomText" parent="android:TextAppearance.DeviceDefault.Small">
<item name="android:textColor">@color/colorLightPurple</item>
</style>
Run Code Online (Sandbox Code Playgroud)
我以编程方式设置最短日期:
calendarView = findViewById( R.id.cv_Calendar );
calendarView.setMinDate( System.currentTimeMillis() );
calendarView.setOnDateChangeListener( (arg0, year, month, date) -> {
GregorianCalendar cal = new GregorianCalendar( year, month, date );
dateInMillis = cal.getTimeInMillis();
} );
Run Code Online (Sandbox Code Playgroud)
知道如何改变颜色吗?
谢谢
我不确定您是否仍然需要这个问题的答案,但如果其他人遇到这个问题,请按照以下步骤操作:
基本上,您需要更改textColor用于引用选择器的属性,该选择器应如下所示:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The color used by the disabled dates (i.e. everything outside the range you set with minDate and maxDate) -->
<item android:color="@color/gray" android:state_enabled="false" />
<!-- The color used by everything else -->
<item android:color="@color/colorLightPurple" />
</selector>
Run Code Online (Sandbox Code Playgroud)
你的风格是:
<style name="CalenderViewDateCustomText" parent="android:TextAppearance.Holo.Small">
<item name="android:textColor">@color/selectorDateTextColor</item>
<item name="android:weekNumberColor">@color/colorLightPurple</item>
</style>
Run Code Online (Sandbox Code Playgroud)
您还可以添加更多状态,例如android:state_activated="true"更改用户选择的日期的文本颜色。
如果您想更改所选日期周围圆圈的颜色,您应该添加<item name="colorControlActivated">@color/blue</item>到CalendarView.
| 归档时间: |
|
| 查看次数: |
1230 次 |
| 最近记录: |