java - 如何禁用 CalendarView 的滚动 - Android Dev
问题描述
我目前正在刷新我的 android 开发技能并遇到了CalendarView组件。我想禁用日历的滚动,而是启用箭头浏览日历。
我想知道以下内容: 如何禁用 CalendarView 的滚动?为什么 Android Studio 在设计器模式中向我显示箭头浏览版本,但编译并运行日历的滚动版本?
我正在运行一个 Android VM,一个带有 API 22 的“Galaxy Nexus”。我还在下面发布了“build.gradle”。
Android 向我展示了什么/我想要什么:
Android Studio 编译和运行的内容:
这里有一些代码:
// activity_main.java:
<?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=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
tools:layout_editor_absoluteX="0dp">
<CalendarView
android:id="@+id/calendarView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:isScrollContainer="false" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
// build.gradle
plugins {
id 'com.android.application'
}
android {
compileSdkVersion 30
buildToolsVersion "30.0.2"
defaultConfig {
applicationId "com.example.kalender003_emptyactivity"
minSdkVersion 16
targetSdkVersion 30
versionCode 1
versionName "1.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
解决方案
使用 MaterialComponents 主题,它很可能会解决问题。
在您的值/主题文件中,用这个替换它们的父级,
parent="Theme.MaterialComponents.DayNight.DarkActionBar"
如果您不想要操作栏,那么,
parent="Theme.MaterialComponents.DayNight.NoActionBar"
如果您只想显示浅色日历视图而不考虑设备的主题使用,
parent="Theme.MaterialComponents.Light.NoActionBar"
推荐阅读
- unity3d - 字符变为纯黑色而不是恢复为原始字符
- java - 不登录?登录错误没有价值?
- java - “2017-09-11 14:28:42”的 Json 反序列化失败,“虽然它似乎适合格式 'yyyy-MM-dd'T'HH:mm:ss.SSS'Z'''
- amazon-web-services - 通过 Greengrass 发送 UID/设备 ID
- php - DateTime 对象不返回语言环境时间
- sql - 组合行号/主键相同的列
- machine-learning - HTK:了解生成的 .mlf 文件中的分数
- javascript - 何时使用过渡与过渡组
- r - 在列表中存储每列(df)的唯一值
- sql - Impala 从列到行,列名消失