How should I import Toolbar tool in android studio?

ⅰ亾dé卋堺 提交于 2019-12-02 08:12:24

问题


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?


回答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


来源:https://stackoverflow.com/questions/58286604/how-should-i-import-toolbar-tool-in-android-studio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!