【问题标题】:Toolbar With Ic_drawer带有 Ic_drawer 的工具栏
【发布时间】:2015-06-05 12:52:24
【问题描述】:

我想要一个带有 ic_drawer 的材质抽屉,但发生的事情是我无法显示我的 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

}

我想要的是材料抽屉应该用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>

【问题讨论】:

  • 您也可以粘贴您的 XML 文件吗?我认为这与布局xml有关。
  • 这是我的 XML 文件 @ss1271 paste.ofcode.org/de8TEj4C5huDSTNiULVQix
  • 请将 XML 粘贴到您的问题中,谢谢
  • 请检查我的答案是否有效?

标签: android material-design android-toolbar


【解决方案1】:

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

所以不要这样:

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

如果有效,请告诉我。

【讨论】:

  • 恐怕您使用工具栏和抽屉的方式有误。您放入工具栏中的图像(抽屉标题)应该在抽屉内。工具栏就像操作栏。你可以在这里找到更多信息android-developers.blogspot.co.uk/2014/10/…
  • 除了我在答案中发布的部分之外,您是否更改了 xml 中的其他内容?
  • 哎呀对不起你 ryt ..我已经把 background_poly 放在工具栏里了..但现在我有一个问题,我可以看到点击那 3 个点
  • 兄弟,我还有一个问题..虽然它已经解决了,但工具栏旁边还有我其他活动的一些内容
  • 你能开始一个新问题吗?因为我的 ATM 有点忙
猜你喜欢
  • 2015-11-09
  • 1970-01-01
  • 1970-01-01
  • 2015-05-02
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多