I am trying to get the TextView
of the Snackbar
with this code snippet:
snackbarView.findViewById<TextView>(android.support.design.R.id.snackbar_text)
but Android Studio does not resolve the design library.
How can I get this code to work?
So, if you want bug fixes or new features that would have previously gone into the Support Library, you need to migrate to AndroidX. Better package management. With AndroidX, you get standardized and independent versioning, as well as better standardized naming and more frequent releases.
Using androidx libraries in your project If you want to use androidx -namespaced libraries in a new project, you need to set the compile SDK to Android 9.0 (API level 28) or higher and set both of the following Android Gradle plugin flags to true in your gradle. properties file. android.
The time is right now to migrate from using the Android Support Library to AndroidX. There are four reasons behind this: The Android Support Library has reached the end of its life. 28.0 was the last release of the Android Support namespace and the namespace is no longer maintained.
Migrating to AndroidX 1 Prerequisites. Before you migrate, bring your app up to date. ... 2 Migrate an existing project using Android Studio. With Android Studio 3.2 and higher, you can migrate an existing project to AndroidX by selecting Refactor > Migrate to AndroidX from the ... 3 Mappings. ... 4 Additional resources. ...
This can come as quite a challenge especially to massive projects that are quite old. Anyone who has tried to use the built in visual studio “Migrate to Android X” feature has probably realised that it doesn’t always work and you’ll run into compilation errors.
The Android Support Library has reached the end of its life. 28.0 was the last release of the Android Support namespace and the namespace is no longer maintained. So, if you want bug fixes or new features that would have previously gone into the Support Library, you need to migrate to AndroidX. Better package management.
Solved with this solution: snackbarView.findViewById<TextView>(com.google.android.material.R.id.snackbar_text)
Thanks for the great answer by @dudi, in general in migration to androidX you can replace
android.support.design.R
with
com.google.android.material.R
I have written a brief step-by-step article on AndroidX migration here, if someone is interested to know more.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With