用CalendarView轻松实现日历布局

 CalendarView是一个日历控件,用它可以快速实现日历布局,而且布局可以左右滑动切换年月,非常方便实用。

我们可以简单的更改它的背景颜色,但是修改不了它的 字体大小和颜色:

要想修改,我们得在values的themes中设置 自定义样式使用:

然后就有如下效果了:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".DateFragment">

<CalendarView
android:id="@+id/calendarView"
android:layout_width="450dp"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:theme="@style/Widget.CalendarView.Custom"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

自定义样式:

<style name="TextAppearance.CalendarDayHeader" parent="TextAppearance.AppCompat.Medium">
<item name="android:textSize">18px</item> <!-- 设置字体大小 -->
<item name="android:textColor">@color/white</item> <!-- 设置字体颜色 -->
</style>
<style name="Widget.CalendarView.Custom" parent="Theme.AppCompat">
<!--周字体颜色-->
<item name="android:weekDayTextAppearance">@style/TextAppearance.CalendarDayHeader</item>
<!--日字体颜色-->
<item name="android:dateTextAppearance">@color/white</item>
<!--选中后背景-->
<item name="colorAccent">@color/black</item>
<item name="colorPrimary">@color/white</item>
<!--选中后字体颜色-->
<item name="android:textColorPrimaryInverse">@color/white</item>
<!--标题颜色-->
<item name="android:textColorPrimary">@color/white</item>
</style>

  • 15
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值