迁移到 AndroidX 后无法解析 android

我试图得到的 SnackbarTextView与这个代码片段:

snackbarView.findViewById<TextView>(android.support.design.R.id.snackbar_text)

但是 Android Studio 并没有解决设计库的问题。

我怎样才能让这个代码工作?

21194 次浏览

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.

You've migrated to AndroidX, which means the library is different now.

(android.support.design.R.id.snackbar_text) to (com.google.android.material.R.id.snackbar_text)

Changing this :

android.support.design.R

with

com.google.android.material.R

solves the problem . After Migration to AndroidX we are working with different library.

As android.support.design.R is no more supported after androidx migration, So you need to replace it

with

com.google.android.material.R