android迁移到androidx报错 AAPT: error: attribute headerLayout (aka com.example.phonehelper:headerLayout)
android迁移到androidx报错 AAPT: error: attribute headerLayout (aka com.example.phonehelper:headerLayout) not found.1.报错详情:2.报错原因<?xml version="1.0" encoding="utf-8"?><androidx.drawerlayout.widget.
·
android迁移到androidx报错 AAPT: error: attribute headerLayout (aka com.example.phonehelper:headerLayout) not found.
1.报错详情:
2.报错原因
<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</LinearLayout>
<!--<com.google.android.material.navigation.NavigationView
app:headerLayout="@layout/layout_header"
android:layout_width="160dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu_left"
>
</com.google.android.material.navigation.NavigationView>-->
<android.support.design.widget.NavigationView
app:headerLayout="@layout/layout_header"
android:layout_width="160dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/menu_left">
</android.support.design.widget.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
今天打算使用androidx.drawerlayout.widget.DrawerLayout实现一个侧滑菜单,由于教程比较旧,原来的布局文件已经不能使用,只好自行升级。由于在<androidx.drawerlayout.widget.DrawerLayout>标签内使用了<android.support.design.widget.NavigationView>标签,导致不兼容,无法找到目标资源文件。
3.解决方法
3.1添加依赖
在build.gradle(:app)下添加依赖
implementation 'com.google.android.material:material:1.0.0-rc01'
关于android迁移到androidx的映射可参照这篇 博客
也可以参考官方文档: 官方文档
3.2修改布局
将上面方框的注释撤销,将下面方框的代码注释掉,完成布局
4.运行效果
更多推荐
所有评论(0)