per*_*000 14 android android-widget android-calendar android-styles
我正在尝试在我的应用程序中添加CalendarView,它使用Theme.Light主题.问题是,此日历的天数以白色呈现,因此在使用灯光主题时,您无法看到它们.
现在,我在XML布局文件中有以下代码:
<CalendarView
android:id="@+id/calendar1"
android:layout_width="500dp"
android:layout_height="300dp"/>
Run Code Online (Sandbox Code Playgroud)
我试图像这样强制日历主题:
<CalendarView
android:id="@+id/calendar1"
android:layout_width="500dp"
android:layout_height="300dp"
android:theme="@android:style/Theme.Light" />
Run Code Online (Sandbox Code Playgroud)
但它没有改变任何东西.我想我应该用android:dateTextAppearance属性做一些事情,所以我尝试了这个:
<CalendarView
android:id="@+id/calendar1"
android:layout_width="500dp"
android:layout_height="300dp"
android:dateTextAppearance="@android:style/TextAppearance.Large.Inverse" />
Run Code Online (Sandbox Code Playgroud)
但它也没有做任何事情.
有任何想法吗 ?
谢谢 !
小智 37
在我的项目中,我在我的主题中定义了属性"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>
Run Code Online (Sandbox Code Playgroud)
所有风格的可能性是:
注意:如果showWeekNumber不能用作xml样式,则可以使用setShowWeekNumber(true)在代码中设置.
我也遇到了很多麻烦.虽然不完美,我还没弄明白如何修改每个方面,但我得到了接近.这就是我做的,在项目的styles.xml中我添加了这两种风格:
<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>
Run Code Online (Sandbox Code Playgroud)
然后,对于CalendarView,我引用了这些样式:
<CalendarView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="@style/CalenderViewCustom"
android:dateTextAppearance="@style/CalenderViewDateCustomText"
android:weekDayTextAppearance="@style/CalenderViewWeekCustomText"/>
Run Code Online (Sandbox Code Playgroud)
您可以将其他类型的颜色(主要/次要)添加到上面的CalenderViewCustom.
| 归档时间: |
|
| 查看次数: |
48211 次 |
| 最近记录: |