Search code examples
androidmaterial-componentsandroid-snackbarmaterial-components-android

Android can't call setAnchorView on material Snackbar


this Snackbar is from package com.google.android.material.snackbar. it extends BaseTransientBottomBar< Snackbar > but there is no snackbar.setAnchorView or snackbar.anchorView. Am I missing anything?

enter image description here

build.gradle

// Android
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'androidx.core:core-ktx:1.1.0'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.android.material:material:1.0.0'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation "androidx.navigation:navigation-fragment-ktx:$nav_version"
    implementation "androidx.navigation:navigation-ui-ktx:$nav_version"

Solution

  • Use:

    implementation 'com.google.android.material:material:1.1.0'
    

    The method setAnchorView was introduced with 1.1.0-alpha01.

    enter image description here