简体   繁体   English

导航抽屉图标在自定义操作栏上不可见?

[英]Navigation Drawer Icon not visible with custom action bar?

I am trying to use navigation drawer with custom action bar. 我正在尝试将导航抽屉与自定义操作栏一起使用。 My action bar does not contain any menu. 我的操作栏不包含任何菜单。
I see that the Navigation Drawer icon, is not visible on the action bar when the drawer is closed. 我看到关闭抽屉时,在操作栏上看不到“导航抽屉”图标。 Even though I have given the drawer icon in the ActionbarToggle implementation. 即使我在ActionbarToggle实现中给出了抽屉图标。 The drawer icon appears when the navigation drawer is open, but disappears when the navigation drawer closes. 抽屉图标在navigation drawer打开时出现,但在navigation drawer关闭时消失。

Activty Activty

 public void setCustomActionBar() {
        ActionBar actionBar = getActionBar();
        actionBar.setCustomView(R.layout.action_bar);
}

NavigationDrawer Fragment NavigationDrawer片段

getActivity(),                    /* host Activity */
        mDrawerLayout,                    /* DrawerLayout object */
        R.drawable.drawer,             /* nav drawer image to replace 'Up' caret */
        R.string.navigation_drawer_open,  /* "open drawer" description for accessibility */
        R.string.navigation_drawer_close  /* "close drawer" description for accessibility */
) {...

As you can see I have provided the drawer icon above. 如您所见,我已经在上方提供了抽屉图标。 Why is this happening and what is the solution to this? 为什么会发生这种情况?解决方案是什么?

I am assuming that you are creating your own custom layout.Suppose I have this xml layout given below: 我假设您正在创建自己的自定义布局,假设我在下面给出了这个xml布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

<FrameLayout 
    android:layout_width="match_parent"
    android:layout_height="45dp"
    android:background="#cccccc">
    <Button 
        android:layout_width="10dp"
        android:id="@+id/drawer_toggle"
        android:layout_height="40dp"
        android:background="#000000"
        android:layout_margin="10dp"
        android:layout_gravity="center_vertical|start"/>
    </FrameLayout>
</LinearLayout>

Then you can do this: 然后,您可以执行以下操作:

Button toggle = (Button) yourDrawerView.findViewById(R.id.drawer_toggle);   
toggle.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                boolean isDrawerOpen = yourDrawerLayoutRefference.isDrawerOpen(yourDrawerLayout);
                if(isDrawerOpen){
                         toggle.closeDrawer(yourDrawerLayout);
                       }
                else{
                       toggle.openDrawer(yourDrawerLayout);
                    }


            }
        }); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM