Android 无法在 Material Snackbar 上调用 setAnchorView

标签 android material-components android-snackbar material-components-android

这个 Snackbar 来自包 com.google.android.material.snackbar 。它扩展了 BaseTransientBottomBar< Snackbar > 但没有 snackbar.setAnchorViewsnackbar.anchorView . 我错过了什么吗?

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"

最佳答案

使用:

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

方法setAnchorView was introduced使用 1.1.0-alpha01

enter image description here

关于Android 无法在 Material Snackbar 上调用 setAnchorView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58950234/

相关文章:

android - 获取离当前时间最近的日期

android - 使用 Xpath 在 Android 中解析 XMl

android - 如何创建一个单击按钮时从底部滑动到顶部的 Android slider ?

android - 如何通过代码圆化 AlertDialog 的角

android - snackbar : how to identify which snackbar is shown

android - 如何为图像按钮的图标赋予强调色?

android - 如何使用 BackdropScaffold 正确实现 Android Compose 嵌套导航

android - 具有透明背景的 BottomAppBar 内的 BottomNavigationView

android - MaterialButtonToggleGroup 上的必需单选

android - Snackbar 的 com.google.android.material.behavior.HideBottomViewOnScrollBehavior 问题