2014-02-10 54 views
0

我正在android抽屜菜單中工作。在此我添加了自定義視圖到操作欄以顯示彈出菜單。它工作正常。當我關閉導航抽屜時,顯示自定義視圖。但我打開抽屜式導航欄我試圖隱藏定製view.Please幫我
代碼:如何隱藏當抽屜打開時的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(); 

    } 
}); 

回答

0

呦可以重寫方法onDrawerOpened(查看drawerView)& onDrawerClosed(查看drawerView)在ActionBarDrawerTohgle:

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); 
相關問題