15

我正在尝试在我的应用程序中添加一个 CalendarView,它使用 Theme.Light 主题。问题是,这个日历的天数是白色的,所以在使用浅色主题时,你看不到它们。

现在,我的 XML 布局文件中有以下代码:

<CalendarView
    android:id="@+id/calendar1"
    android:layout_width="500dp"
    android:layout_height="300dp"/>

我试图像这样强制日历主题:

<CalendarView
    android:id="@+id/calendar1"
    android:layout_width="500dp"
    android:layout_height="300dp"
    android:theme="@android:style/Theme.Light" />

但这并没有改变任何东西。我想我应该对 android:dateTextAppearance 属性做点什么,所以我尝试了这个:

<CalendarView
    android:id="@+id/calendar1"
    android:layout_width="500dp"
    android:layout_height="300dp"
    android:dateTextAppearance="@android:style/TextAppearance.Large.Inverse" />

但它也没有做任何事情。

有任何想法吗 ?

谢谢 !

4

2 回答 2

41

在我的项目中,我在主题中定义了属性“android:calendarViewStyle”。

<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) 进行设置。

于 2012-03-26T09:07:06.397 回答
13

我也遇到了很多麻烦。虽然并不完美,而且我还没有弄清楚如何修改各个方面,但我已经接近了。我就是这样做的,在项目的 styles.xml 中我添加了这些样式:

<style name="CalenderViewCustom" parent="Theme.AppCompat">
    <item name="colorAccent">@color/white_30</item>
</style>

<style name="CalenderViewDateCustomText" parent="android:TextAppearance.DeviceDefault.Small">
    <item name="android:textColor">@color/white</item>
</style>

<style name="CalenderViewWeekCustomText" parent="android:TextAppearance.DeviceDefault.Small">
    <item name="android:textColor">@color/white_30</item>
</style>

然后,对于 CalendarView,我这样引用了这些样式:

<CalendarView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/CalenderViewCustom"
    android:dateTextAppearance="@style/CalenderViewDateCustomText"
    android:weekDayTextAppearance="@style/CalenderViewWeekCustomText"/>

您可以将其他类型的颜色(主要/次要)添加到上面的 CalenderViewCustom。

于 2017-05-10T19:14:35.303 回答