如何在抽屉打开时隐藏操作栏自定义视图

时间:2014-02-10 11:17:14

标签: android android-actionbar

我在android导航抽屉菜单中工作。在此我添加了自定义视图到Actionbar显示弹出菜单。它工作正常。当我关闭导航抽屉我显示自定义视图。但我打开导航抽屉我试图隐藏自定义视图。请帮帮我 代码:

ActionBar actionBar = getSupportActionBar();
    actionBar.setCustomView(R.layout.customaactionlayout);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME

                    | ActionBar.DISPLAY_HOME_AS_UP | ActionBar.DISPLAY_SHOW_TITLE

                    | ActionBar.DISPLAY_USE_LOGO | ActionBar.DISPLAY_SHOW_CUSTOM);

    actionBar.setDisplayShowTitleEnabled(true);

    actionBar.getCustomView().findViewById(R.id.custombutton);

   customSettings=(Button) findViewById(R.id.custombutton);
  customSettings.setOnClickListener(new View.OnClickListener() {

    @Override
    public void onClick(View v) {

           PopupMenu popup = new PopupMenu(NavigationActivity.this, customSettings);  
            //Inflating the Popup using xml file  
            popup.getMenuInflater().inflate(R.menu.main, popup.getMenu());  
            popup.show();

    }
});

1 个答案:

答案 0 :(得分:0)

Yo可以重写方法onDrawerOpened(View drawerView)& ActionBarDrawerTohgle中的onDrawerClosed(查看drawerView):

 mDrawerToggle = new SherlockActionBarDrawerToggle(
                this,                  /* host Activity */
                mDrawerLayout,         /* DrawerLayout object */
                R.drawable.ic_drawer,  /* nav drawer image to replace 'Up' caret */
                R.string.app_name,  /* "open drawer" description for accessibility */
                R.string.action_settings  /* "close drawer" description for accessibility */
        ) {
            public void onDrawerClosed(View view) {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }

            @Override
            public void onDrawerOpened(View drawerView) {
                invalidateOptionsMenu(); // creates call to onPrepareOptionsMenu()
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);