Change navigation drawer selected item with replace fragment - android

I have Navigation Drawer with default code. But, when I want to replace my fragments. Navigation Drawer menu selected item background color is not changing.
I have 2 fragments. First saving data to sqlite db and replacing to second fragment. Now I want to change background of second fragment with java code.
navigation drawer
I want to change item background color, when I'm in a fragment.(if fragment A, background color is on. if fragment B, background color is on)
Thanks.

I think you can show the selected item by putting android:checkable="true" on the menu item.

Related

NavigationComponent with BottomNavigationView fragment progress

I'm using NavigationComponent with BottomNavigationView.
I'm facing with a problem thats when i select first item in BottomNavigationView then go from fragment 1->2->3 after that i change selection to second item in BottomNavigationView. When i reselect first item in BottomNavigationView i'm losing fragment progress in first selected item.
The scheme of what is now
A scheme of what I want to achieve
How can i manage it?

How to set toolbar.setNavigationOnClickListener only for current fragment?

Started new project from navigation drawer activity template. By default, all drawer menu items are at the same navigation level. All fragments display hamburger menu button, that shows drawer.
I need to keep all items in drawer, but place Home as top level item and others as it's children like this:
Tried to overwrite toolbar?.setNavigationOnClickListener { } in Gallery fragment, but it also affects Home fragment and I didn't find how to restore default behavior.
How can I set Home as navigation parent for others or how to set navigation click listener to only one fragment?
For example you have set tag for every fragment to trace when you start new fragment and now check with Home and set click event..
Fragment home = getSupportFragmentManager().findFragmentByTag("home");

grid data change dynamically inside Fragment inside Sliding tab on click

I have a sliding tab layout where i have 3 tabs and a navigation drawer. Each tab is a fragment. now i want to use one fragment as a cardview in a grid manner. but my problem is when i click navigation drawer item my tab fragment grid data is not changing.
here is the link of my code structure.
https://github.com/rrrongon/NavigationDrawerwithTab
Use event bus for achieve this. when you click on menu item fire an event and than listen that event to your respective fragment and on listen do your respective work

Android navigation drawer set clickable area only to list items

I am using a NavigationDrawer in my application and I am loading in the drawer a ListView. When the drawer is opened, it covers almost half of an Activity which contains also a ListView.
The problem that I face is that if I tap on the drawer(not on an item contained in the drawer), a ListView item from my Activity gets the click event and then starts an activity associated with that list item.
Is it possible to restrict the clickable area of the drawer only to the list items?
I assume your drawer layout is more complex than just a simple ListView, if you have place to tap on the drawer.
In that case, you could simple specify
android:clickable="true" for your top drawer layout (LinearLayout, RelativeLayout or whatever you use).

Change Navigation Drawer selected item from within Fragment

I have a navigation drawer in my main activity, and 2 fragments (A and B). The Navigation has two items (A and B). When the application is started the main activity shows and displays fragment A in the FrameLayout.
Fragment A contains a button that replaces the FrameLayout content to Fragment B. The .replace works fine, but I'm not sure how to change the selected drawer item from A to B.
Jayesh helped me with this... didn't realize it was easy. For those interested in my main activity (which hosts the navigation drawer):
public static void changeDrawerItem(int Position) {
mDrawerList.setItemChecked(1, true);
}
Note: mDrawerList is my Drawer List. Not sure if this is the best way to change the item, but it'll allow me to change the drawer item from other fragments I create.
In the fragment I simply call the method with
MainActivity.changeDrawerItem(1);

Categories

Resources