[英]how to customize calendar view in jetpack compose?
I'm using the calendar view in the bottom sheet to show the calendar view.我正在使用底部工作表中的日历视图来显示日历视图。 Now I want to change the navigation left and right arrow icon and decrease space between both icons in Calendar.现在我想更改导航左右箭头图标并减少日历中两个图标之间的空间。 I also wanted the "Today" text label when today's date is selected like below.我还想要“今日”文本label当今天的日期选择下面的日期时。
Currently I'm getting view like:目前我得到这样的观点:
This is the view I want to get:这是我想要获得的视图:
Row(modifier = Modifier
.padding(6.dp),
verticalAlignment = Alignment.Top) {
AndroidView(
{ CalendarView(it) },
modifier = Modifier.wrapContentWidth(),
update = { views ->
views.date = scheduleViewModel.selectedCalender.value.timeInMillis
views.setOnDateChangeListener { calendarView, year, month, dayOfMonth ->
val cal = Calendar.getInstance()
cal.set(year, month, dayOfMonth)
scheduleViewModel.onEvent(ScheduleEvent.DateSelected(cal))
onDateSelect()
}
}
)
Text(
text = "Today",
modifier = Modifier
.wrapContentWidth(),
fontFamily = appFontFamily,
fontWeight = FontWeight.SemiBold,
fontSize = 10.sp,
color = Color(0xFF0A70C4),
textAlign = TextAlign.Center,
)
}
When you're working with XML views, you need to look for non Compose solutions, eg check out answers under this question how to define a custom XML theme for CalendarView
.当您使用 XML 视图时,您需要寻找非 Compose 解决方案,例如查看此问题下的答案如何为CalendarView
定义自定义 XML 主题。
To apply the theme to AndroidView
you can use ContextThemeWrapper
:要将主题应用于AndroidView
,您可以使用ContextThemeWrapper
:
AndroidView(
{ CalendarView(ContextThemeWrapper(it, R.style.your_custom_style)) },
// ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.