我对此主题进行了大量搜索。我做了以下事情:
- 通过 SDK 管理器确保支持库是最新的。
- 进入构建路径以及顺序和导出选项卡以确保检查依赖项。
- 清理我的项目并重新启动 adt。
- 右键单击项目 -> android 工具 -> 添加支持库。
我已经在另一个项目中使用了支持库,它工作正常,但我没有使用抽屉布局。下面是我在活动类中调用的 xml 文件。调用时会发生此错误setContentView(R.layout.main_sliding_layout);
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/frame_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView
android:id="@+id/list_slidermenu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@color/list_divider"
android:dividerHeight="1dp"
android:listSelector="@drawable/list_selector"
android:background="@color/list_background"/>
</android.support.v4.widget.DrawerLayout>
在最新版本中:
如果您正在使用androidx 支持库 then,
Use:
androidx.drawerlayout.widget.DrawerLayout
代替:
android.support.v4.widget.DrawerLayout
and
Use:
com.google.android.material.navigation.NavigationView
代替:
android.support.design.widget.NavigationView
对于其他等效的 androidx 类,请参阅以下链接:https://developer.android.com/jetpack/androidx/migrate https://developer.android.com/jetpack/androidx/migrate
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)