2012-02-23 75 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。