/** * Change the drawer indicator * * @param resource - The icon * @return DrawerActivity */ public DrawerActivity setCustomIconNavigationDrawer(int resource) { if (mDrawerToggle != null) { mDrawerToggle.setHomeAsUpIndicator(resource); mDefaultToolbar.setNavigationIcon(resource); } return this; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mDrawer = (DrawerLayout) findViewById(R.id.drawer); if (savedInstanceState == null) { getSupportFragmentManager() .beginTransaction() .add(R.id.contentcontainer, new MainFragment()) .commit(); LeftMenuFragment menuFragment = new LeftMenuFragment(); menuFragment.setDrawerLayout(mDrawer); getSupportFragmentManager().beginTransaction().add(R.id.leftmenu, menuFragment).commit(); getSupportFragmentManager() .beginTransaction() .add(R.id.rightmenu, new RightMenuFragment()) .commit(); } mDrawer.setDrawerShadow(R.drawable.drawer_shadow, GravityCompat.START); // mDrawer.setDrawerListener(new DrawerListener() { // // @Override // public void onDrawerStateChanged(int state) { // // } // // @Override // public void onDrawerSlide(View view, float slideOffset) { // switch(view.getId()) { // case R.id.leftmenu : // int level = (int)(slideOffset * 10000); // icon.setLevel(level); // break; // case R.id.rightmenu : // // } // } // // @Override // public void onDrawerOpened(View view) { // switch(view.getId()) { // case R.id.leftmenu : // case R.id.rightmenu : // Toast.makeText(MainActivity.this, "drawer opened", Toast.LENGTH_SHORT).show(); // } // } // // @Override // public void onDrawerClosed(View view) { // switch(view.getId()) { // case R.id.leftmenu : // case R.id.rightmenu : // Toast.makeText(MainActivity.this, "drawer closed", Toast.LENGTH_SHORT).show(); // } // } // }); getSupportActionBar().setDisplayHomeAsUpEnabled(true); mToggle = new ActionBarDrawerToggle(this, mDrawer, R.string.open_desc, R.string.close_desc) { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); Toast.makeText(MainActivity.this, "drawer closed", Toast.LENGTH_SHORT).show(); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); Toast.makeText(MainActivity.this, "drawer open", Toast.LENGTH_SHORT).show(); } }; mToggle.setHomeAsUpIndicator(R.drawable.ic_drawer); mDrawer.setDrawerListener(mToggle); // icon = getResources().getDrawable(R.drawable.ic_home_as_up); // getSupportActionBar().setHomeAsUpIndicator(icon); }