所以,我尝试在活动中添加菜单,我做了我读过的书中的所有内容,但是我总是会收到此错误:
找不到以下类:
- android.support.design.widget.AppBarLayout (Fix Build Path, Edit XML, Create Class) - android.support.design.widget.CoordinatorLayout (Fix Build Path, Edit XML, Create Class) - android.support.v7.widget.Toolbar (Fix Build Path, Edit XML, Create Class) Tip: Try to build the project. Tip: Try to refresh the layout.
我的布局xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.AppBarLayout>
<android.support.v7.widget.Toolbar>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>
</LinearLayout>
在build:gradle(Mdoule:app)中,我也实现了库:
implementation 'com.android.support:appcompat-v7:30.0.0'
implementation 'com.android.support:design:30.0.0'
因为支持库v.30 不存在。
//implementation 'com.android.support:appcompat-v7:30.0.0'
//implementation 'com.android.support:design:30.0.0'
您必须使用androidx库和材料组件库:
用途:
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
并且在您的布局中:
<androidx.coordinatorlayout.widget.CoordinatorLayout>
<com.google.android.material.appbar.AppBarLayout>
<com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.MaterialToolbar>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>