-2

Here is my OnOptionItemSelected() and three other method for Toggle button如何使我的ActionBar切換按鈕在我的應用程序中工作?

這我有切換按鈕,在MainActivity

  mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, 
      R.drawable.humberg, //nav menu toggle icon 
      R.string.app_name, // nav drawer open - description for accessibility 
      R.string.app_name // nav drawer close - description for accessibility 
    ) { 
     public void onDrawerClosed(View view) { 
      getActionBar().setTitle(mTitle); 
      // calling onPrepareOptionsMenu() to show action bar icons 
      invalidateOptionsMenu(); 
     } 

     public void onDrawerOpened(View drawerView) { 
      getActionBar().setTitle(mDrawerTitle); 
      // calling onPrepareOptionsMenu() to hide action bar icons 
      invalidateOptionsMenu(); 
     } 
    }; 
    mDrawerLayout.setDrawerListener(mDrawerToggle); 
    // Drawer Item click listeners 
    mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { 
     @Override 
     public void onItemClick(AdapterView<?> parent, View view, int position, long id) { 
      selectItemFromDrawer(position); 
     } 

當我運行我的應用程序即時得到錯誤,如很遺憾,您APLLICATION已經停止被寫入了一段代碼.. }); This is my Logcat

回答

0

你的問題來自onPrepareOptionMenu()方法,你實際上不會給任何菜單文件充氣活動,在設置顯示或隱藏菜單項之前用此方法填充你的自定義菜單文件。 ps:我的英語sr

0

錯誤說:RelativeLayout不能投到DrawerLayout這是一個ClassCastException

方式:

拋出,表明代碼已經試圖將對象強制轉換到 子類的它不是一個實例。

Explanation of "ClassCastException" in Java

,或者意味着你正在聲明一些類型的變量/對象並將其分配給您所定義

另一種類型的
相關問題