kanytu / android-material-drawer-template

An Android template with navigation drawer for material design
Apache License 2.0
674 stars 217 forks source link

Make Menu Icons Invisable when Navigation Drawer is open (Fragments of ViewPager) #44

Open nurzhannogerbek opened 9 years ago

nurzhannogerbek commented 9 years ago

Hello! First of all thank you for this great project!

I have some problems and I hope you know solution. I have MainActivity with ViewPager which had 3 Fragment. Each Fragment has there own menu items in toolbar. Inside of my MainActivity I added your beautiful Navigation drawer. I want to make menu icons in toolbar invisable when Navigation Drawer is open. (no matter what fragment open)

In your project you used it: @Override public boolean onCreateOptionsMenu(Menu menu) { if (!mNavigationDrawerFragment.isDrawerOpen()) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.menu_main, menu); return false; } return super.onCreateOptionsMenu(menu); }

Unfortunatly I have 3 menu files for each fragment and I am little bit comfused how to set all of them here. I experemented but I have no results. How I can fix it?

My second question is about customization of Navigation Drawer. Inside of NavigationDrawerFragment we have Navigation items list but how to add dividers between items. I want to make something like sections inside of Navigation drawer. It is little bit problematically with that list.

Thank you again for project! Have a nice day! Gob bless you!

kanytu commented 9 years ago

Hello. First of all do you know how to set up different menus for each fragment? You need to call setHasOptionsMenu. Next override onCreateOptionsMenu and apply the menu layout there. You don't have to change anything on the activity code apart from changing "return false" to "return true".

For the dividers you can add a new item onto the list, with a different name and change it's layout when you bind the view.

Keep in mind that none of this questions are in fact an issue with the library/template itself. These are android questions and therefor should be asked on a forum for the effect. Also this template is deprecated and I no longer support it.

Have a nice day.

nurzhannogerbek commented 9 years ago

Hello man! Actually, I know how to set menu. As a matter of fact I wrote before that I had menu for each Fragment of my ViewPager. I set menu inside each Fragment with setHasOptionsMenu. I am not sure that you understand my problem exactly. Let me try explaine it. I have 2 Fragment. Each of them had menu. I have also main_menu which is visiable to both of Fragment. I tried to us code below in MainActivity but only items in main_menu became invisable when navigation drawer open. I changed return false to true and on the contrary. It didnt help me. That menu items which I set in Fragments visable when I open Navigation Drawer. Only items of main_menu became invisable when you open NavDrawer. How to make Fragment menu also invisable when use open NavDrawer.

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (!mNavigationDrawerFragment.isDrawerOpen()) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main & R.menu.menu_weather & R.menu.menu_map, menu);
        return true;
    }
    return super.onCreateOptionsMenu(menu);
}

main_menu - menu which visable in both of Fragments menu_weather - menu of first Fragment (visible only in first Fragment) menu_map - menu of second Fragment (visible only in second Fragment)

I hope you understand me. What can you advise to me now?

kanytu commented 9 years ago

As far as I know you don't have to add that if condition on your fragments. Just on the main activity. On your fragments you just have to inflate and nothing else.

nurzhannogerbek commented 9 years ago

Can you check it please. I didnt understand exactly what you mean. Here below code which I used to set menu in one of my Fragment. With second fragment I used the same code only changed menu file name. If you know solution of my problem please let me know it please.

FirstFragment.java @Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { //Code here setHasOptionsMenu(true); } @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater.inflate(R.menu.menu_map, menu); super.onCreateOptionsMenu(menu, inflater); }

kanytu commented 9 years ago

Like I said...This is not an issue with the library. You need to search somewhere else for help. This is a good place to start (1min searching on google): http://stackoverflow.com/questions/21831698/how-to-hide-optionsmenu-on-navigationdrawer-using-fragments

Just add:

@Override
public void onPrepareOptionsMenu(Menu menu) {
    if (mDrawerLayout != null && isDrawerOpen()) {
        menu.clear();
    }
}

On NavigationDrawerFragment and you should be good to go

nurzhannogerbek commented 9 years ago

Unfortunatly it didnt work for me. Anyway Thanks and sorry for such questions here. I just make my first steps in android programming! Thank you for your wonderful project and good luck in your job! =)