在导航抽屉中未显示三个破折号或抽屉图标

时间:2019-10-02 14:23:57

标签: android navigation-drawer

  • 我正在使用物料导航视图。
  • 导航抽屉工作正常。
  • 但是我的应用程序中没有显示三个破折号按钮(抽屉按钮)。
  • 请提供一些准确的解决方案,我已经花了很多时间。
  • 我不想直接导航
  

activity_main

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

java

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'
  

菜单(drawer_menu)

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

drawer_header.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>

0 个答案:

没有答案