更改 CalendarView 样式 [英] Change CalendarView style
问题描述
我正在尝试在我的应用程序中添加一个 CalendarView,它使用 Theme.Light 主题.问题是,这个日历的天数是用白色渲染的,所以在使用浅色主题时,你看不到它们.
I'm trying to add a CalendarView in my application, which uses the Theme.Light theme. The problem is, the days numbers of this calendar are rendered in white, so while using a light theme, you can't see them.
现在,我的 XML 布局文件中有以下代码:
Right now, I have the following code in my XML layout file :
<CalendarView
android:id="@+id/calendar1"
android:layout_width="500dp"
android:layout_height="300dp"/>
我试图像这样强制日历主题:
I tried to force the calendar theme like this :
<CalendarView
android:id="@+id/calendar1"
android:layout_width="500dp"
android:layout_height="300dp"
android:theme="@android:style/Theme.Light" />
但它并没有改变任何东西.我想我应该对 android:dateTextAppearance 属性做一些事情,所以我尝试了这个:
But it doesn't change anything. I think I should do something with the android:dateTextAppearance property, so I tried this :
<CalendarView
android:id="@+id/calendar1"
android:layout_width="500dp"
android:layout_height="300dp"
android:dateTextAppearance="@android:style/TextAppearance.Large.Inverse" />
但它也没有做任何事情.
but it doesn't do anything either.
有什么想法吗?
谢谢!
推荐答案
在我的项目中,我在我的主题中定义了属性android:calendarViewStyle".
In my project I defined the attribute "android:calendarViewStyle" in my theme.
<style name="Theme.Custom" parent="@android:Theme">
<item name="android:calendarViewStyle">@style/Widget.CalendarView.Custom</item>
</style>
<style name="Widget.CalendarView.Custom" parent="android:Widget.CalendarView">
<item name="android:focusedMonthDateColor">@color/cs_textcolor</item>
<item name="android:weekNumberColor">@color/red</item>
<item name="android:weekDayTextAppearance">@style/TextAppearance.Medium</item>
<item name="android:dateTextAppearance">@style/TextAppearance.Medium</item>
</style>
所有样式的可能性是:
- @attr ref android.R.styleable#CalendarView_showWeekNumber
- @attr ref android.R.styleable#CalendarView_firstDayOfWeek
- @attr ref android.R.styleable#CalendarView_minDate
- @attr ref android.R.styleable#CalendarView_maxDate
- @attr ref android.R.styleable#CalendarView_shownWeekCount
- @attr ref android.R.styleable#CalendarView_selectedWeekBackgroundColor
- @attr ref android.R.styleable#CalendarView_focusedMonthDateColor
- @attr ref android.R.styleable#CalendarView_unfocusedMonthDateColor
- @attr ref android.R.styleable#CalendarView_weekNumberColor
- @attr ref android.R.styleable#CalendarView_weekSeparatorLineColor
- @attr ref android.R.styleable#CalendarView_selectedDateVerticalBar
- @attr ref android.R.styleable#CalendarView_weekDayTextAppearance
- @attr ref android.R.styleable#CalendarView_dateTextAppearance
注意:如果 showWeekNumber 不能作为 xml 样式,您可以在代码中使用 setShowWeekNumber(true) 进行设置.
这篇关于更改 CalendarView 样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!