material-components-android-codelabs icon indicating copy to clipboard operation
material-components-android-codelabs copied to clipboard

MDC-102 ProductGridFragment.java imports wrong Toolbar library

Open acutetech opened this issue 6 years ago • 2 comments

The instructions clearly state "When importing the Toolbar class, make sure you import androidx.appcompat.widget.Toolbar and not android.widget.Toolbar"

Yet the code shows: import android.widget.Toolbar;

The finished-codelab code is correct.

acutetech avatar Jun 08 '19 17:06 acutetech

Note: I'm a beginner to java and android dev as well as github, so let me know if said anything wrong or posted in the wrong format.

I was getting an error "error: incompatible types: android.widget.Toolbar cannot be converted to androidx.appcompat.widget.Toolbar" while building the app.

The code snippet where the error was shown is here: private void setUpToolbar(View view) { Toolbar toolbar = view.findViewById(R.id.app_bar); AppCompatActivity activity = (AppCompatActivity) getActivity(); if (activity != null) { activity.setSupportActionBar(toolbar); } }

"Toolbar toolbar = view.findViewById(R.id.app_bar);" seems to call the android.widget.Toolbar library which cannot be type casted to the androidx.appcompat.widget.Toolbar library in the "activity.setSupportActionBar(toolbar);" line.

I fixed it by initiating the toolbar as "androidx.appcompat.widget.Toolbar toolbar = view.findViewById(R.id.app_bar)" but this seems to cause the toolbar to turn white instead of blue as shown in the picture. Is this a possible fix and what can be done about the color?

Sriven-Reddy avatar Jul 06 '19 07:07 Sriven-Reddy

It is now November 7, 2020 --- why hasn't this mistake been corrected.

Should I even trust the rest of these tutorials .

We should not have to be learning by finding mistakes in "tutorials" meant to teach us capabilities.

Very disappointing!

ErstwhileWork avatar Nov 08 '20 02:11 ErstwhileWork