2012-02-23 35 views
9

Tôi đang cố thêm một CalendarView trong ứng dụng của mình, sử dụng chủ đề Theme.Light. Vấn đề là, số ngày của lịch này được hiển thị bằng màu trắng, vì vậy trong khi sử dụng chủ đề sáng, bạn không thể nhìn thấy chúng.Thay đổi kiểu CalendarView

Ngay bây giờ, tôi có đoạn mã sau vào file layout XML của tôi:

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

tôi đã cố gắng để buộc các chủ đề lịch như thế này:

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

Nhưng nó không thay đổi bất cứ điều gì. Tôi nghĩ tôi nên làm điều gì đó với thuộc tính android: dateTextAppearance, vì vậy tôi đã thử điều này:

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

nhưng cũng không làm gì cả.

Bất kỳ ý tưởng nào?

Cảm ơn!

Trả lời

28

Trong dự án của tôi, tôi đã xác định thuộc tính "android: calendarViewStyle" trong chủ đề của mình.

<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> 

Tất cả các phong cách khả năng là:

  • @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 and roid.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

lưu ý: nếu showWeekNumber không làm việc như kiểu xml, bạn có thể đặt trong mã với setShowWeekNumber (thật).

+0

Có đúng không?

+2

không thể thay đổi chủ đề màu bằng giải pháp trên –

+0

Bạn có thể giải thích thêm một chút về điều này không? Tôi sử dụng tất cả những thứ "@attr" ở đâu? Tôi không quen với điều đó chút nào. –

5

Tôi cũng gặp nhiều rắc rối. Trong khi không hoàn hảo, và tôi đã không tìm ra cách để sửa đổi mọi khía cạnh, tôi đã gần gũi. Đây là cách tôi đã làm nó, trong phong cách của dự án.xml tôi bổ sung thêm hai phong cách này:

<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> 

Sau đó, cho CalendarView tôi tham khảo những phong cách như vậy:

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

Bạn có thể thêm các loại màu sắc (tiểu học/trung học) để CalenderViewCustom trên.

Các vấn đề liên quan