2

I am trying to add a Toolbar to my android studio project. I found several explanations of how should I do it and they all explained these steps. In the first step, I should import android.support.v7.widget.Toolbar; but it does not succeed: The v7 characters bulbing in red and the warning message is: "Cannot resolve symbol 'v7'". I tried to replace the v7 with v4 which is included in the suggestions bar after the import android.support.____ but when I do so, the android studio claims it "cannot resolve symbol 'widget'".

How can I import the Toolbar tool successfully?

Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841
J. Doe
  • 299
  • 3
  • 12

1 Answers1

1

Since you are using Androidx libraries you have to:

  • use the right class in your code import androidx.appcompat.widget.Toolbar.
  • use the right AppCompativity: import androidx.appcompat.app.AppCompatActivity;
  • use <androidx.appcompat.widget.Toolbar in your layout

If you want to use the Material Components Library

  • add the library implementation 'com.google.android.material:material:<version>'
  • follow the getting started page to change the theme to a Theme.MaterialComponents.* theme
  • Use the com.google.android.material.appbar.MaterialToolbar in your code and in your layout
Gabriele Mariotti
  • 320,139
  • 94
  • 887
  • 841