2012-02-23 77 views
9

我想在我的应用程序中添加一个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" /> 

但它也没有做任何事情。

任何想法?

谢谢!

回答

28

在我的项目中,我在我的主题中定义了属性“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裁判android.R.styleable#CalendarView_showWeekNumber
  • @attr裁判android.R.styleable#CalendarView_firstDayOfWeek
  • @attr裁判android.R .styleable#CalendarView_minDate
  • @attr ref android.R.styleable#CalendarView_maxDate
  • @attr ref and roid.R.styleable#CalendarView_shownWeekCount
  • @attr裁判android.R.styleable#CalendarView_selectedWeekBackgroundColor
  • @attr裁判android.R.styleable#CalendarView_focusedMonthDateColor
  • @attr裁判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裁判android.R.styleable#CalendarView_weekDayTextAppearance
  • @attr裁判android.R.styleable#CalendarView_dateTextAppearance

注:如果showWeekNumber不是XML的工作作风,你可以与setShowWeekNumber代码中设置(真正)。

+0

它是正确的吗? 2014-06-06 06:50:02

+2

无法更改使用上述溶液 – 2014-06-06 07:02:21

+0

你能否解释多了几分这个颜色主题?我在哪里使用所有这些“@attr”的东西?我对此一点都不熟悉。 – 2016-03-08 00:09:46

5

我一直有很多麻烦。虽然不完美,我还没有想出如何修改每个方面,我接近了。这就是我在项目风格中做到的。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。