ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

android – 更改CalendarView样式

2019-09-17 15:24:52  阅读:250  来源: 互联网

标签:android-calendar android android-styles android-widget


我正在尝试在我的应用程序中添加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-calendar,android,android-styles,android-widget
来源: https://codeday.me/bug/20190917/1809438.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有