javaandroidcalendarview

How to disable scrolling for CalendarView - Android Dev


I am currently refreshing my android developement skills and came across the CalendarView component. I wanted to disable the scrolling of the calendar and instead enable the arrows to browse through the calendar.

What I want to know is the following: How can I disable the scrolling from the CalendarView? And why does Android Studio show me the arrow browse-version in the Designer-Mode but compiles and runs the scroll-version of the calendar?

I am running an Android VM, a "Galaxy Nexus" with API 22. I also posted the "build.gradle" further below.

What Android shows me/What I want:

enter image description here

What Android Studio compiles & runs:

enter image description here


Here some code:

// 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'
}

Solution

  • Thanks to Vaibhav Goyal i came across the solution.

    The API level I used was to low (API 22, Android 5.1). Changing that to API 23 (Android 6.0) solved my problem. Now it shows me the CalendarView with arrow-navigation instead of the scroll version!