首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >更改CalendarView样式

更改CalendarView样式
EN

Stack Overflow用户
提问于 2012-02-23 19:45:58
回答 2查看 58.3K关注 0票数 15

我正尝试在使用Theme.Light主题的应用程序中添加一个CalendarView。问题是,这个日历的天数是用白色呈现的,所以当使用轻主题时,你看不到它们。

现在,我的XML布局文件中有以下代码:

代码语言:javascript
复制
<CalendarView
    android:id="@+id/calendar1"
    android:layout_width="500dp"
    android:layout_height="300dp"/>

我试着像这样强制日历主题:

代码语言:javascript
复制
<CalendarView
    android:id="@+id/calendar1"
    android:layout_width="500dp"
    android:layout_height="300dp"
    android:theme="@android:style/Theme.Light" />

但这不会改变任何事。我想我应该对android:dateTextAppe现属性做点什么,所以我尝试了一下:

代码语言:javascript
复制
<CalendarView
    android:id="@+id/calendar1"
    android:layout_width="500dp"
    android:layout_height="300dp"
    android:dateTextAppearance="@android:style/TextAppearance.Large.Inverse" />

但是它也不能做任何事情。

有什么想法吗?

谢谢!

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-03-26 17:07:06

在我的项目中,我在主题中定义了"android:calendarViewStyle“属性。

代码语言:javascript
复制
<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>

所有可能的样式是:

ref ref @attr ref android.R.styleable#CalendarView_showWeekNumber

  • @attr ref android.R.styleable#CalendarView_firstDayOfWeek

  • @attr ref android.R.styleable#CalendarView_minDate

  • @attr ref 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 refandroid.R.styleable#CalendarView_unfocusedMonthDateColor

  • @attr参考android.R.styleable#CalendarView_weekNumberColor

  • @attr参考android.R.styleable#CalendarView_weekSeparatorLineColor

  • @attr参考android.R.styleable#CalendarView_selectedDateVerticalBar

  • @attr参考android.R.styleable#CalendarView_weekDayTextAppearance

  • @attr参考android.R.styleable#CalendarView_dateTextAppearance

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

票数 41
EN

Stack Overflow用户

发布于 2017-05-11 03:14:35

我也遇到了很多麻烦。虽然不是完美的,我也没有想出如何修改每个方面,但我接近了。这就是我是如何做到的,在项目的styles.xml中我添加了这些样式:

代码语言:javascript
复制
<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>

然后,对于CalendarView,我这样引用了这些样式:

代码语言:javascript
复制
<CalendarView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:theme="@style/CalenderViewCustom"
    android:dateTextAppearance="@style/CalenderViewDateCustomText"
    android:weekDayTextAppearance="@style/CalenderViewWeekCustomText"/>

您可以将其他类型的颜色(原色/次色)添加到上面的CalenderViewCustom中。

票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9412402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档