Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drawer selected item #16

Closed
hamen opened this issue Mar 12, 2015 · 2 comments
Closed

Drawer selected item #16

hamen opened this issue Mar 12, 2015 · 2 comments

Comments

@hamen
Copy link

hamen commented Mar 12, 2015

Hi
Thanks for the useful library.
I'm trying to achieve a two levels navigation.
I'm using a BaseActivity that creates the common navigation drawer.

MainActivity extends BaseActivity and shows the first fragment.
Every navigation drawer item replaces a fragment. These fragments contain lists.
If I click the second navigation drawer item, it correctly replaces the fragment and select the item in the navigation drawer.

Clicking a list item opens a DetailActivity. DetailActivity extends BaseActivity, so I have the common navigation drawer. Now, I have a few needs:

  • Setting the toolbar icon to something like a left-arrow, instead of the hamburger
  • Setting the proper "selected" item in the navigation drawer.
    Any help?

If you think I'm using the wrong approach, please, let me. I'd appreciate feedbacks.
Thanks

@madcyph3r
Copy link
Owner

For your icon problem:
use this method:

    public void yourMethod() {
        // shows a back button, instead of the drawer icon
        drawer.showActionBarMenuIcon(MaterialNavigationDrawer.ActionBarMenuItem.BACK);
        // lock the drawer to close
        drawer.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);
        // set your custom icon, if you don't want the back icon
        drawer.getSupportActionBar().setHomeAsUpIndicator();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Get item selected and deal with it
        switch (item.getItemId()) {
            case android.R.id.home:
                //yout home button action here
                Toast.makeText(getActivity(), "your action. you can use here the back pattern, if you want", Toast.LENGTH_LONG).show();
                return true;
        }

        return super.onOptionsItemSelected(item);
    }

For more see here:
https://github.com/madcyph3r/AdvancedMaterialDrawer/blob/master/example/src/main/java/de/madcyph3r/example/tools/ActionBarButtons.java
and here:
https://github.com/madcyph3r/AdvancedMaterialDrawer/blob/master/example/src/main/java/de/madcyph3r/example/tools/ActionBarButtons/FragmentActionBarButtons.java

For your second problem:
get the section you need and call select();

// Example:
// the below method select's the second section, from your current menu. Devisor and label items will be ignored in the getSection function.
// Example: this is your order:
// section 1
// devisor
// section 2

// to select section 2, you must give the position 1 not 2.

drawer.getCurrentMenu().getSection(1).select();

@hamen
Copy link
Author

hamen commented Mar 12, 2015

Smooth! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants