工具栏 Ic_drawer

Toolbar With Ic_drawer

我想要一个带 ic_drawer 的 material 抽屉,但我无法显示我的 ic_drawer 尽管导航抽屉工作正常

我关注了这个tutorial

这是我的输出

我做过这样的事

  frameLayout= (FrameLayout)findViewById (R.id.content_frame);
    toolbar = (Toolbar) findViewById(R.id.tool_bar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(true);



    mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View

    mRecyclerView.setHasFixedSize(true);                            // Letting the system know that the list objects are of fixed size

    mAdapter = new MyAdapter(TITLES,ICONS,NAME,EMAIL,PROFILE);       // Creating the Adapter of MyAdapter class(which we are going to see in a bit)
    // And passing the titles,icons,header view name, header view email,
    // and header view profile picture

    mRecyclerView.setAdapter(mAdapter);                              // Setting the adapter to RecyclerView

    mLayoutManager = new LinearLayoutManager(this);                 // Creating a layout Manager

    mRecyclerView.setLayoutManager(mLayoutManager);                 // Setting the layout Manager


    Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout);

          // Drawer object Assigned to the view


    mDrawerToggle = new ActionBarDrawerToggle(this,Drawer,toolbar,R.string.drawer_open,R.string.drawer_close){

        @Override
        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is
            // open I am not going to put anything here)
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            super.onDrawerClosed(drawerView);
            // Code here will execute once drawer is closed
        }



    }; // Drawer Toggle Object Made
    Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle
    mDrawerToggle.syncState();               // Finally we set the drawer toggle sync State

}

我想要的是material抽屉应该显示ic_drawer

需要输出

这是我的XML

  <?xml version="1.0" encoding="utf-8"?>

xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/DrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:elevation="7dp">


<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <include
        android:id="@+id/tool_bar"
        layout="@layout/toolbar">
    </include>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World" />

</LinearLayout>
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</FrameLayout>

<android.support.v7.widget.RecyclerView
    android:id="@+id/RecyclerView"
    android:layout_width="320dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"

    android:background="#ffffff"
    android:scrollbars="vertical">

</android.support.v7.widget.RecyclerView>


</android.support.v4.widget.DrawerLayout>

DrawerLayout 使用类似 FrameLayout 的方式来组织视图的 z 顺序。

所以不是这个:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <include
        android:id="@+id/tool_bar"
        layout="@layout/toolbar">
    </include>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World" />

</LinearLayout>
<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</FrameLayout>

将你的 content_frame 放在你的 tool_bar 之前,像这样:

<FrameLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
</FrameLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">


    <include
        android:id="@+id/tool_bar"
        layout="@layout/toolbar">
    </include>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World" />

</LinearLayout>

因此,您的 Toolbar 将位于您的 Drawer

之上

如果有效请告诉我。