2017-12-27 457 views
-2

我想更改我的導航抽屜圖標。但是當我更改圖標後,應用程序崩潰。錯誤代碼顯示了布爾值,這令我很難理解。我找不到我的失敗。我是否以錯誤的方式執行它? 對不起,但我是Android Studio的新手,這個問題可能有點不必要。但嘗試了很多解決問題。但是,我還找不到解決方案。如何更改導航抽屜圖標?

這是MainClass。我在OnCreate方法之外生成了一個變量。

public class MainActivity extends AppCompatActivity { 

    private DrawerLayout mDrawerLayout; 
    ExpandableListAdapter mMenuAdapter; 
    ExpandableListView expandableList; 
    List<ExpandedMenuModel> listDataHeader; 
    HashMap<ExpandedMenuModel, List<String>> listDataChild; 

    ActionBarDrawerToggle mDrawerToggle; 

    Drawable drawable; 

    WebView webView; 
    Toolbar toolbar; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_navigation_view); 

     mDrawerToggle.setDrawerIndicatorEnabled(false); 

     drawable = ResourcesCompat.getDrawable(getResources(), R.drawable.ic_menu_gallery, getTheme()); 

     mDrawerToggle.setHomeAsUpIndicator(drawable); 
     mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) { 
        mDrawerLayout.closeDrawer(GravityCompat.START); 
       } else { 
        mDrawerLayout.openDrawer(GravityCompat.START); 
       } 
      } 
     }); 

     ........ 

回答

1
mDrawerToggle = ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.drawer_open, R.string.drawer_close); 
mDrawerToggle.setDrawerIndicatorEnabled(false); 
mDrawerToggle.setToolbarNavigationClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View v) { 
       if (mDrawerLayout.isDrawerVisible(GravityCompat.START)) { 
        mDrawerLayout.closeDrawer(GravityCompat.START); 
       } else { 
        mDrawerLayout.openDrawer(GravityCompat.START); 
       } 
      } 
     }); 
mDrawerToggle.setHomeAsUpIndicator(R.drawable.ic_menu_gallery); 

詳細檢查了這link

+0

我試過了。它不起作用 –

0

你還沒有指定值:上調用setDrawerIndicatorEnabled這裏之前

mDrawerToggle 

mDrawerToggle.setDrawerIndicatorEnabled(false); 
+0

沒有我在方法之外做? –

+0

不,請看這裏:https://developer.android.com/training/implementing-navigation/nav-drawer.html如何實現它 – marcinj