gpt4 book ai didi

android - 如何更改 CalendarView 中的月份文本颜色

转载 作者:行者123 更新时间:2023-11-30 05:07:23 26 4
gpt4 key购买 nike

我在我的项目中使用了CalendarView,我需要为它做一个特殊的设计。我可以更改 CalendarView 中所有内容的颜色,但不能更改日历顶部月份的颜色。我尝试了 xml 中的所有属性。我如何更改月份铭文和箭头的颜色?

<CalendarView
android:id="@+id/calendarID"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="Heh"
android:maxDate="31/12/2018"
android:minDate="09/01/2012"
android:showWeekNumber="false"
android:focusedMonthDateColor="@android:style/TextAppearance.Small"
android:background="#004366"
android:unfocusedMonthDateColor="@android:style/TextAppearance.Small"
android:dateTextAppearance="@android:style/TextAppearance.Small"
android:weekDayTextAppearance="@android:style/TextAppearance.Small"
android:weekSeparatorLineColor="@android:style/TextAppearance.Small"
android:selectedWeekBackgroundColor="@android:style/TextAppearance.Small"
/>

enter image description here

 LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService
(Context.LAYOUT_INFLATER_SERVICE);

LinearLayout ll= (LinearLayout)inflater.inflate(R.layout.calendar_moi, null, false);

CalendarView cv = (CalendarView) ll.getChildAt(0);
Long maxData = System.currentTimeMillis();
cv.setMaxDate(maxData);

cv.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {

@Override
public void onSelectedDayChange(CalendarView view, int year, int month,
int dayOfMonth) {


}
});

new AlertDialog.Builder(ItemClassActivity.this)
.setTitle("")
.setMessage("")
.setView(ll)
.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

}
}).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {

}
}
).show();

最佳答案

styles.xml 中定义如下:

<style name="CustomCalendarMonth" parent="AppTheme">
<item name="android:textColorPrimary">@color/orange</item>
</style>

<style name="CustomCalendarDay" parent="TextAppearance.MaterialComponents.Caption">
<item name="android:textColor">@color/green</item>
</style>

<style name="CustomCalendarWeek" parent="TextAppearance.MaterialComponents.Caption">
<item name="android:textColor">@color/purple</item>
</style>

然后在 xml 中:

<CalendarView
android:theme="@style/CustomCalendarMonth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:dateTextAppearance="@style/CustomCalendarDay"
android:weekDayTextAppearance="@style/CustomCalendarWeek" />

输出如下:

关于android - 如何更改 CalendarView 中的月份文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54343589/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com