android - 在导航抽屉中,三个破折号或抽屉图标未显示
问题描述
- 我正在使用材质导航视图。
- 导航抽屉工作正常。
- 但是我的应用程序中没有显示三个破折号按钮(抽屉按钮)。
- 请给出一些准确的解决方案,我已经花了很多时间在上面。
- 我不想直接导航
活动主
<androidx.drawerlayout.widget.DrawerLayout
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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
tools:context=".MainActivity">
<com.google.android.material.navigation.NavigationView
app:headerLayout="@layout/drawer_header"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#FFFFFF"
app:itemTextColor="#2d2d2d"
app:itemIconTint="#AAD825"
app:menu="@menu/drawer_menu"
android:layout_gravity="start"/>
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/recyclerView" />
</androidx.drawerlayout.widget.DrawerLayout>
爪哇
private DrawerLayout mdrawerLayout;
private ActionBarDrawerToggle mToggle;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mdrawerLayout=(DrawerLayout) findViewById(R.id.drawer_layout);
mToggle= new ActionBarDrawerToggle(this,mdrawerLayout,R.string.open,R.string.close);
mdrawerLayout.addDrawerListener(mToggle);
getSupportActionBar().setDefaultDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
mToggle.syncState();
recyclerView = (RecyclerView) findViewById(R.id.recyclerView);
recyclerView.setHasFixedSize(true);
recyclerView.setLayoutManager(new GridLayoutManager(this,3));
loadProducts();
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if (mToggle.onOptionsItemSelected(item)){
return true;
}
return super.onOptionsItemSelected(item);
}
依赖
implementation 'com.android.support:design:29.0.2'
implementation 'com.android.support:support-v4:29.0.2'
菜单(抽屉菜单)
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:title="Home Page" android:id="@+id/home_page" android:icon="@drawable/home_icon"></item>
<item android:title="Search Car" android:id="@+id/search_car" android:icon="@drawable/search_icon"></item>
<item android:title="My Profile" android:id="@+id/my_profile" android:icon="@drawable/profile"></item>
<item android:title="Update Profile" android:id="@+id/update_profile" android:icon="@drawable/profile_update_icon"></item>
<item android:title="Log Out" android:id="@+id/logout" android:icon="@drawable/logout_icon"></item>
</menu>
抽屉头.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#C5E075">
<ImageView
android:layout_gravity="center"
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/draw_photo"
android:src="@mipmap/ic_launcher" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Your Name"
android:textStyle="bold"
android:id="@+id/draw_text"
android:layout_gravity="center"
android:textSize="25dp"
android:textColor="#2d2d2d"/>
</LinearLayout>
细绳
<resources>
<string name="app_name">Bs</string>
<string name="open">Open</string>
<string name="close">Close</string>
</resources>
解决方案
推荐阅读
- python - Django 的 manage.py 显示旧命令
- python - 如何使用 CreateSession 启动 pbap 会话
- python - 在 Jupyter Notebook 中显示 Pandas DataFrame
- c++ - 'reinterpret_cast':无法使用 boost.dll 从 'overloaded-function' 转换为 'intptr_t'
- java - Querydsl InnerJoin DTO
- maple - 如何在 GR-tensor 包中使用系列?
- python - 在我的 jupyter 笔记本中安装fuzzywuzzy 库时出错
- microsoft-translator - 自定义翻译 API 授权
- c# - c# SOAP web service 复杂类型
- gwt - 本地使用码头的 Gwt 项目致命错误