首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带有Ic_drawer的工具栏

带有Ic_drawer的工具栏
EN

Stack Overflow用户
提问于 2015-06-05 12:52:24
回答 1查看 313关注 0票数 0

我想要一个带ic_drawer的材料抽屉,但是我不能显示我的ic_drawer,尽管导航抽屉工作得很好

我跟踪了这个教程

这是我的输出

我做过这样的事

代码语言:javascript
复制
  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

}

我想要的是材料抽屉应该和ic_drawer一起显示

所需输出

这是我的XML

代码语言:javascript
复制
  <?xml version="1.0" encoding="utf-8"?>
代码语言:javascript
复制
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>
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-05 13:15:48

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

所以,不是这样的:

代码语言:javascript
复制
<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之前,如下所示:

代码语言:javascript
复制
<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之上

如果有用请告诉我。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30667055

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档