NavigationComponent with BottomNavigationView fragment progress - android

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?

Related

How to get to the original Fragment from Bottom Navigation View?

I am facing a challenge in the app that i am developing.
I have a BottomNavigationView with 4 Fragments:
Home Feed Notification Profile
Home is the home fragment of my NAV GRAPH.
Lets suppose Home has a button and on click of it, it goes to CartFragment. Now i click to Feed by using BottomNavigationView. So now, when i click on home fragment again from BottomNavigation view...i see the CartFragment whereas i want to see the HomeFragment. And it doesn't even show the HomeFragment tab active on the bottomNavigationView, it is like it completely replaces it.
I am not able to switch to my original fragment whenever i click on a tab from BottomNavigationView
If you want to reset your backstack when you press one of the bottom nav items, use below code where you define bottom nav view and this will solve your problem:
yourBottomNavView.setOnItemSelectedListener { item ->
NavigationUI.onNavDestinationSelected(item, yourNavController)
yourNavController.popBackStack(item.itemId, inclusive = false)
true
}
Just change yourBottomNavView and yourNavController with yours.

Hiding a BottomNavigationView during a fragment transition

I am creating an app using single Activity so on main_activity I set the fragment as NavHostFragment and on the bottom the BottomNavigationView.
In fragment A (first tab selected), If I click on button_1...navigate on a new fragment (A1). Of course inside fragment A1 I need to hide BottomNavigationView so on main_activity I am using addOnDestinationChangedListener to hide BottomNavigationView.
The problem is that if I want use a transition (enter, exit, popup_enter, popup_exit) the BottomNavigationView hide immediatly. (example 1 on image)
How can I do to have the same as example 2 on image?
It looks like you have your 'NavHostFragment' below the 'BottomNavigationView'. So even if you were to delay hiding the BottomNavigationView the fragment transition would still happen behind it. So without changing your implementation completely it won't be possible to have the new fragment transition above the bottom BottomNavigationView.

Change navigation drawer selected item with replace fragment

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.

animate an item from fragment adapter to its parent activity

I have a layout like this :
I have activity, inside of activity is a fragment and a box, inside of the fragment is a recyclerview (ex. list of song title and image)
Activity -> Fragment -> RecyclerViewAdapter
I'm using this animation, it is working well but the problem is the
animation moves only inside the fragment area. (based on the pic I want it to animate an item from recyclerview going to the box)
holder.rl_main_layout.animate().x(xValue).y(yValue);
so can anyone suggest an Idea to do what I want?
Fly item from recycler view to cart icon on toolbar
Please check this link , this will guide you how you can accomplish your problem
Check this link

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

Categories

Resources