2012-02-23 3 views
9

Theme.Light 테마를 사용하는 응용 프로그램에 CalendarView를 추가하려고합니다. 문제는이 달력의 요일 번호가 흰색으로 렌더링되므로 가벼운 테마를 사용하는 동안 볼 수 없다는 것입니다.CalendarView 스타일 변경

는 지금, 내 XML 레이아웃 파일에 다음 코드를 가지고 :

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

을하지만 아무것도 변경하지 않습니다

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

이 같은 일정 테마를 강제로 시도했다. 나는 안드로이드 뭔가해야한다 생각한다 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.style # CalendarView_maxDate
  • @attr ref roid.R.styleable # CalendarView_shownWeekCount
  • @attr android.R.styleable 심판 # CalendarView_selectedWeekBackgroundColor
  • @attr 심판 android.R.styleable # CalendarView_focusedMonthDateColor
  • @attr 심판 android.R.styleable # CalendarView_unfocusedMonthDateColor
  • @ ATTR는 android.R.styleable # CalendarView_weekNumberColor에게 @attr 심판 android.R.styleable # CalendarView_selectedDateVerticalBar
  • @attr android.R.styleable 심판 # CalendarView_weekSeparatorLineColor
  • 을 심판
  • @attr 심판 android.R.styleable # CalendarView_weekDayTextAppearance
  • @attr android.R.styleable 심판 # CalendarView_dateTextAppearance

참고 : showWeekNumber하지 XML 스타일로 작업하는 경우, 당신은 setShowWeekNumber와 코드에서 설정할 수 있습니다 (참된).

+0

맞습니까?

+2

위의 해결책을 사용하여 색상 테마를 변경할 수 없습니다. –

+0

좀 더 자세히 설명해 주시겠습니까? "@attr"모든 것을 어디에 사용합니까? 나는 그것에 익숙하지 않다. –

5

저는 많은 문제도있었습니다. 완벽하지는 않지만 모든면을 수정하는 방법을 찾지 못해서 가까워졌습니다. 이것이 프로젝트의 스타일에서 내가 한 방식입니다.

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

당신은 (주/보조)는 위의 CalenderViewCustom하는 색상의 다른 유형을 추가 할 수 있습니다 : 나는 그래서 그 스타일을 참조 CalendarView을 위해, 그리고

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

: XML 나는이 두 가지 스타일을 추가했습니다.