Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
166 views
in Technique[技术] by (71.8m points)

android - Change CalendarView style

I'm trying to add a CalendarView in my application, which uses the Theme.Light theme. The problem is, the days numbers of this calendar are rendered in white, so while using a light theme, you can't see them.

Right now, I have the following code in my XML layout file :

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

I tried to force the calendar theme like this :

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

But it doesn't change anything. I think I should do something with the android:dateTextAppearance property, so I tried this :

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

but it doesn't do anything either.

Any ideas ?

Thanks !

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

In my project I defined the attribute "android:calendarViewStyle" in my theme.

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

All styles possibilities are:

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

note: if showWeekNumber not work as xml style, you can set in the code with setShowWeekNumber(true).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...