SNM
SNM

Reputation: 6785

Navigation Component is not replacing current fragment activity

So, I'm trying to navigato from one Fragment to another, I have used this line

val action = MapsFragmentDirections.nextAction(marker?.title!!)
            findNavController().navigate(action)

this navigation goes to another Fragment, But in the time it reachs that fragment, I see the activity below my fragment and my fragment is transparent with the recyclerview above.

I have researched and found that I need to se replace with FragmentTransaction, but I think that is done in the background of Navigation Component.

The problem is that when inflating my other fragment, I can see my activity below the view of the fragment.

A temporary fix is to put the background of the RecyclerView as blank, but I dont want to fix it that way, I want it to be inflated like a normal fragment without seeing nothing under it

My problem is exactly this one : Fragment is transparent and shows Activity below

But I need to solve it with Navigation Component, and I dont see any method that helps me do that.

Or does I need to set all my view inside a fragment> tag in my xml ?

Thanks

Upvotes: 1

Views: 1358

Answers (1)

ianhanniballake
ianhanniballake

Reputation: 199795

When using NavController, you shouldn't be doing any separate FragmentTransactions at all - as long as you've added a NavHostFragment to your XML and are using the app:navGraph attribute to specify your graph, the NavController does all the work on switching between Fragments and making sure they don't overlap.

Upvotes: 2

Related Questions