gpt4 book ai didi

android - 更改 CalendarView 样式

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:31:10 26 4
gpt4 key购买 nike

我正在尝试在我的应用程序中添加一个 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" />

但它也没有做任何事情。

有什么想法吗?

谢谢!

最佳答案

在我的项目中,我在我的主题中定义了属性“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 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

注意:如果 showWeekNumber 不是 xml 样式,您可以在代码中使用 setShowWeekNumber(true) 进行设置。

关于android - 更改 CalendarView 样式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9412402/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com