2012-02-23 14 views
9

Próbuję dodać CalendarView w mojej aplikacji, która używa motywu Theme.Light. Problem polega na tym, że liczby dni tego kalendarza są renderowane na biało, więc podczas używania motywu light nie można ich zobaczyć.Zmień styl CalendarView

Teraz, Mam następujący kod w moim pliku XML szablonu:

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

Próbowałem zmusić temat kalendarza tak:

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

Ale to niczego nie zmienia. Myślę, że należy zrobić coś z Androidem: własność dateTextAppearance, więc próbowałem to:

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

ale nie robi nic albo.

Wszelkie pomysły?

Dzięki!

Odpowiedz

28

W moim projekcie zdefiniowałem w moim motywie atrybut "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> 

Wszystkie możliwości są 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 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 Opłaty 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

uwaga: jeśli nie działa jak showWeekNumber stylu xml można ustawić w kodzie z setShowWeekNumber (prawdziwe).

+0

Czy to prawda?

+2

nie można zmienić motywu kolorystycznego za pomocą powyższego rozwiązania –

+0

Czy możesz rozwinąć trochę więcej na ten temat? Gdzie używam tych wszystkich rzeczy "@attr"? W ogóle o tym nie wiem. –

5

Mam również wiele problemów. Chociaż nie jest idealny, a nie wymyśliłem, jak zmodyfikować każdy aspekt, zbliżyłem się. Tak to zrobiłem w stylach projektu.xml dodałem te dwa style:

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

Następnie za CalendarView I odwołuje takie style jak tak:

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

można dodać inne rodzaje kolorów (pierwotne/wtórne) do CalenderViewCustom powyżej.