Android Bottom Navigation with Navigation Component's NavigationUI change destination - android

While creating bottom navigation with the jetpack navigation component the code below would work for an activity
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment) as NavHostFragment
val navController = navHostFragment.navController
findViewById<BottomNavigationView>(R.id.bottom_nav).setupWithNavController(navController)
with that, while working inside with fragments you need to call .setupWithNavController and pass in the navController and all should be fine.
But in my case with a navgraph inside the fragments XML and bottom navigation specified the app build but its only stuck in the home screen.
MainFragment.kt
class MainFragment : Fragment() {
private var _binding: FragmentMainBinding? = null
private val binding get() = _binding!!
override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = FragmentMainBinding.inflate(inflater, container, false)
NavigationUI.setupWithNavController(binding.bottomNav,findNavController())
return binding.root
}
override fun onDestroyView() {
super.onDestroyView()
_binding = null
}
}
fragment_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.MainFragment">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="#menu/bottom_navigation_menu" />
<fragment
android:id="#+id/main_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/main_graph" />
</androidx.constraintlayout.widget.ConstraintLayout>
main_graph.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/main_gragh"
app:startDestination="#id/homeFragment">
<fragment
android:id="#+id/homeFragment"
android:name="io.github.jerrymatera.medstab.ui.home.HomeFragment"
android:label="fragment_home"
tools:layout="#layout/fragment_home" />
<fragment
android:id="#+id/appointmentFragment"
android:name="io.github.jerrymatera.medstab.ui.appointment.AppointmentFragment"
android:label="appointment_fragment"
tools:layout="#layout/appointment_fragment" />
<fragment
android:id="#+id/chatFragment"
android:name="io.github.jerrymatera.medstab.ui.chat.ChatFragment"
android:label="chat_fragment"
tools:layout="#layout/chat_fragment" />
<fragment
android:id="#+id/profileFragment"
android:name="io.github.jerrymatera.medstab.ui.profile.ProfileFragment"
android:label="profile_fragment"
tools:layout="#layout/profile_fragment" />
</navigation>
menu/bottom_navigation_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/mainFragment"
android:icon="#drawable/ic_home_24"
android:title="#string/home" />
<item
android:id="#+id/appointmentFragment"
android:enabled="true"
android:icon="#drawable/ic_date_range_24"
android:title="#string/appointments" />
<item
android:id="#+id/chatFragment"
android:enabled="true"
android:icon="#drawable/ic_chat_24"
android:title="#string/chat" />
<item
android:id="#+id/profileFragment"
android:enabled="true"
android:icon="#drawable/ic_account_box_24"
android:title="#string/profile" />
</menu>

In menu resource of NavigationView (menu/bottom_navigation_menu.xml) each item ID must be matching with fragment ID in navigation graph(main_graph.xml). By this NavigationUI will figure out mapping between item and destination and it will perform fragment transaction on item selection.
change
android:id="#+id/mainFragment"
to
android:id="#+id/homeFragment"
in menu/bottom_navigation_menu.xml

Maybe the problem is in MainFragment.kt but I don't know the exact reason
NavigationUI.setupWithNavController(binding.bottomNav,findNavController())
require BottomNavigationView and NavController

Related

Bottom navigation does not show icon and text

I created a bottom navigation in main activity and does not show menu icon or text
I use the material library version 1.7.0
I changed the version to 1.6.1 and 1.5, but there was still a problem
I invalidate caches and the problem was not solved
I also used the clean project/rebuild project, but the problem was not solved
what is the problem?
activity_main.xml
<layout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools">
<data>
</data>
<androidx.coordinatorlayout.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<RelativeLayout
android:id="#+id/mainActivityBase"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/app_name"
android:gravity="center"
android:textAppearance="?textAppearanceHeadline4"
android:layout_marginTop="25dp"/>
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_container"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="64dp"
android:clipToPadding="false"
app:defaultNavHost="true"
app:navGraph="#navigation/nav_movie_player"
tools:layout="#layout/fragment_home" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationMain"
android:layout_width="match_parent"
android:layout_height="64dp"
android:layout_alignParentBottom="true"
android:layout_marginStart="#dimen/marginStart"
android:layout_marginEnd="#dimen/marginEnd"
android:layout_marginBottom="#dimen/marginStart"
android:elevation="8dp"
app:labelVisibilityMode="unlabeled"
app:menu="#menu/movie_player_menu"
app:itemIconSize="28dp"
app:itemRippleColor="#android:color/transparent"
/>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
</layout>
movie_player_menu.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="#+id/homeFragment"
android:title="#string/home"
android:icon="#drawable/ic_round_home_24" />
<item android:id="#+id/searchFragment"
android:title="#string/search"
android:icon="#drawable/ic_round_search_24" />
<item android:id="#+id/profileFragment"
android:title="#string/profile"
android:icon="#drawable/ic_round_person_24" />
</menu>
Navigation components setup
private lateinit var navController: NavController
private lateinit var appBarConfiguration: AppBarConfiguration
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = DataBindingUtil.setContentView(this, R.layout.activity_main)
binding.lifecycleOwner = this
setupBottomNavigationBar()
}
private fun setupBottomNavigationBar() {
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottomNavigationMain)
val navHostFragment = supportFragmentManager.findFragmentById(
R.id.nav_host_container
) as NavHostFragment
navController = navHostFragment.navController
bottomNavigationView.setupWithNavController(navController)
appBarConfiguration = AppBarConfiguration(
setOf(R.id.homeFragment, R.id.searchFragment, R.id.profileFragment)
)
}
override fun onSupportNavigateUp(): Boolean {
return navController.navigateUp(appBarConfiguration)
}
I run it on a physical phone but the problem was still there
Update
I found the problem set windowTranslucentNavigation false and problem is solved

BottomNavigationView does not respond to clicks

I can't bind Bottom Navigation View to FragmentContainerView. Clicks on the Bottom Navigation View have no effect.
Code:
fragment_tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".screen.fragment.TabsFragment"
xmlns:tools="http://schemas.android.com/tools"
>
<androidx.fragment.app.FragmentContainerView
android:id="#+id/containerView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:name="androidx.navigation.fragment.NavHostFragment"
app:navGraph="#navigation/graph_navigation_tabs"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigationView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/menu_tabs"
app:itemIconTint="#color/white"
app:itemTextColor="#color/white"
android:background="#color/blue_dark"
/>
</LinearLayout>
TabsFragment.kt
class TabsFragment : Fragment(R.layout.fragment_tabs)
{
private lateinit var binding : FragmentTabsBinding
override fun onCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
savedInstanceState: Bundle?
): View {
binding = FragmentTabsBinding.inflate(layoutInflater, container, false)
val navHost = childFragmentManager.findFragmentById(R.id.containerView) as NavHostFragment
val navView: BottomNavigationView = binding.bottomNavigationView
val navController = navHost.navController
NavigationUI.setupWithNavController(navView, navController)
return binding.root
}
}
graph_navigation_tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/graph_navigation_tabs"
app:startDestination="#id/graph_shop">
<include app:graph="#navigation/graph_shop" />
<include app:graph="#navigation/graph_favorite" />
<include app:graph="#navigation/graph_shopping_card" />
<include app:graph="#navigation/graph_profile" />
</navigation>
menu_tabs.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/Explorer"
android:title="Explorer"
android:icon="#drawable/ic_explorer_dot"
/>
<item
android:id="#+id/buy"
android:title="Shop"
android:icon="#drawable/ic_buy"
/>
<item
android:id="#+id/favorite"
android:title="Favorite"
android:icon="#drawable/ic_favorite"
/>
<item
android:id="#+id/profile"
android:title="Profile"
android:icon="#drawable/ic_profile"
/>
</menu>
I tried using newview.setupWithNavController(NavController), but it didn't help
I tried to replace nested graphs with ordinary fragments, but the effect is the same
Your bottomNavigation doesn't toggle fragments because your menu items id must be the same as the included navgraph name.
Example:
In your nav_graph.xml
<include app:graph="#navigation/graph_shop" />
In your menu.xml
<item
android:id="#+id/graph_shop"
...
/>

Problem with bottom navigation when app goes to background

My version of nav is 2.4.2
My problem is that when the app goes to background the bottomNav doesn't work after re enter the app in some situations.
For example, I am in the third nav. I leave the app with the home button and if I open the app again all works correctly. But if I start to open a lot of apps and after entering my app the bottomNav doesn't work. It changes the symbol colors, but doesn't navigate. The backstacks of the current nav still work.
And here is my code to set the navigation.
MainActivity
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
if(savedInstanceState == null){
setupBottomNavigationBar()
}
}
private fun setupBottomNavigationBar(){
val graphs = setOf(
R.id.firstFragment,
R.id.secondFragment,
R.id.thirdFragment,
R.id.fourthFragment,
R.id.fithFragment
)
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_container) as NavHostFragment
currentNavController = navHostFragment.navController
val bottomNavigation = findViewById<BottomNavigationView>(R.id.bottom_navigation)
bottomNavigation.setupWithNavController(currentNavController)
appBarConfiguration = AppBarConfiguration(graphs)
}
activityMain.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".activities.MainActivity">
<androidx.fragment.app.FragmentContainerView
android:id="#+id/nav_host_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:name="androidx.navigation.fragment.NavHostFragment"
app:defaultNavHost="true"
app:navGraph="#navigation/super_nav"
/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:menu="#menu/bottom_nav"
app:itemIconTint="#drawable/botton_navigation_colors"
app:labelVisibilityMode="unlabeled"
app:itemIconSize="35dp"
/>
bottom_nav.xml
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/first_navigation"
android:icon="#drawable/ic_first_black"
android:contentDescription="#string/first_desc"
android:title="#string/first_title" />
<item
android:id="#+id/second_navigation"
android:icon="#drawable/ic_second"
android:contentDescription="#string/second_desc"
android:title="#string/second_title" />
<item
android:id="#+id/third_navigation"
android:icon="#drawable/ic_third"
android:contentDescription="#string/third_desc"
android:title="#string/third_title" />
<item
android:id="#+id/fourth_navigation"
android:icon="#drawable/ic_fourth"
android:contentDescription="#string/fourth_desc"
android:title="#string/fourth_title" />
<item
android:id="#+id/fifth_navigation"
android:icon="#drawable/ic_fifth"
android:contentDescription="#string/fifth_desc"
android:title="#string/fifth_title" />
super_nav.xml
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/super_nav"
app:startDestination="#+id/main_navigation">
<include app:graph="#navigation/first_navigation"/>
<include app:graph="#navigation/second_navigation"/>
<include app:graph="#navigation/third_navigation" />
<include app:graph="#navigation/fourth_cart_navigation" />
<include app:graph="#navigation/fifth_navigation" />

Android jetpack navigation does not work after adding multiple back stack support [2.4.+]

I updated the navigation library from 2.3.5 to 2.4.2. After update I started getting this error: java.lang.IllegalArgumentException: No destination with ID XXX is on the NavController's back stack. The current destination is null. The error occurs after the following steps: FirstFragment -> SecondFragment [with another BottomNavigationView] -> ThirdFragment -> SecondFragment [crash]
I'll try to describe what I'm doing:
I have two fragments with BottomNavigationView.
First Fragment
class MainBottomNavFragment : Fragment() {
private lateinit var navController: NavController
override fun onStart() {
super.onStart()
if (!::navController.isInitialized) {
navController =
Navigation.findNavController(requireActivity(), R.id.mainBottomNavHostFragment)
}
binding.bottomNavigation.setupWithNavController(navController)
}
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="#+id/mainBottomNavHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="false"
app:layout_constraintBottom_toTopOf="#+id/bottomNavigation"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/main_menu_nav_graph" />
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/bottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:menu="#menu/main_menu" />
</androidx.constraintlayout.widget.ConstraintLayout>
main_menu_nav_graph
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/main_bottom_nav_graph"
app:startDestination="#id/first">
<fragment
android:id="#+id/first"
android:name=".FirstFragment"
android:label="FirstFragment" />
<fragment
android:id="#+id/second"
android:name=".SecondFragment"
android:label="SecondFragment" />
<fragment
android:id="#+id/third"
android:name=".ThirdFragment"
android:label="ThirdFragment">
<action
... />
</fragment>
<navigation
android:id="#+id/fourth"
app:startDestination="#id/fourthFragment">
<fragment
android:id="#+id/fourthFragment"
android:name=".FourthFragment"
android:label="FourthFragment" />
<fragment
android:id="#+id/fourthFragmentA"
android:name=".FourthFragmentA"
android:label="FourthFragmentA" />
<fragment
android:id="#+id/fourthFragmentB"
android:name=".FourthFragmentB"
android:label="FourthFragmentB" />
</navigation>
</navigation>
Second Fragment looks like this:
class SecondFragment : Fragment() {
private lateinit var navController: NavController
override fun onStart() {
super.onStart()
if (!::navController.isInitialized) {
navController = Navigation.findNavController(requireActivity(), R.id.secondHostFragment)
val inflater = navController.navInflater
navController.setGraph(inflater.inflate(R.navigation.second_nav_graph), arguments)
}
binding.secondBottomNavigation.setupWithNavController(navController)
}
}
Layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="#+id/secondBottomNavigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:menu="#menu/second_menu" />
<fragment
android:id="#+id/secondHostFragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/secondBottomNavigation" />
</androidx.constraintlayout.widget.ConstraintLayout>
second_nav_graph
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="#+id/second_nav_graph"
app:startDestination="#id/secondA">
<fragment
android:id="#+id/secondA"
android:name=".SecondA"
android:label="SecondA">
<action
... />
</fragment>
<fragment
android:id="#+id/secondB"
android:name=".SecondB"
android:label="SecondB" />
</navigation>
Can I have two nested BottomNavigationView? In version 2.3.5 everything worked

InflateException while implementing Navigation Library

I am applying navigation library to my project.
And I get this error:
android.view.InflateException: Binary XML file line #23: Binary XML file line #23: Error inflating class fragment
This is MainActivity.kt:
val fragmentManager = supportFragmentManager
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
if(savedInstanceState == null){
fragmentManager.beginTransaction().add(R.id.nav_host_fragment, InitFragment()).commit()
}else{
}
}
This is activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
</data>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000"
android:tint="#555"
tools:context="com.example.view.main.MainActivity">
<ImageView
android:id="#+id/iv_flame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
<fragment
android:id="#+id/nav_host_fragment"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:defaultNavHost="true"
app:navGraph="#navigation/nav_graph"/>
</RelativeLayout>
</layout>
This is InitFragment.kt
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
var binding = DataBindingUtil.inflate<FragmentInitBinding>(inflater, R.layout.fragment_init, container, false)
binding!!.initVm = InitViewModel(this#InitFragment)
var view = binding.root
return view
}
this is fragment_init.xml
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:bind="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="initVm"
type="com.example.vm.InitViewModel" />
</data>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/transparent"
tools:context=".view.main.fragment.LoginFragment">
</layout>
I don't see any problem with this code. Is there any extra job I have to implement for this? I am using Data Binding. But I don't think I need to it for MainActivity.kt.
MainActivity.kt contains all the fragments. And initFragment.kt will be the first navigation that has menu to navigate.
What should I do?
Edit: In case of JAVA and NOT KOTLIN
after setContentView()
add
Fragment fragment = findViewById(R.id.nav_host_fragment);
Basically an initialization error.
AccountActivity :
class AccountActivity : AppCompatActivity(){
private lateinit var activityAccountBinding: ActivityAccountBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val binding = DataBindingUtil.setContentView<ViewDataBinding>(this,
R.layout.activity_account)
setDataBinder(binding)
setup()
}
override fun setDataBinder(viewDataBinding: ViewDataBinding) {
activityAccountBinding = viewDataBinding as ActivityAccountBinding
// to getting events in this file(Click event)
activityAccountBinding.accountActivity = this
}
override fun setup() {
}
}
activity_account:-
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<data>
<variable
name="accountActivity"
type="com.app.presentation.myaccount.activity.AccountActivity"
/>
</data>
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/red_fd3d50">
<fragment
android:id="#+id/fragmentContainer"
android:name="androidx.navigation.fragment.NavHostFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:defaultNavHost="true"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="#navigation/my_account_graph"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
my_account_graph:-
<?xml version="1.0" encoding="utf-8"?>
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/my_account_graph"
app:startDestination="#id/profileFragment">
<fragment
android:id="#+id/profileFragment"
android:name="com.app.presentation.myaccount.ProfileFragment"
android:label="ProfileFragment"
tools:layout="#layout/fragment_profile" />
</navigation>

Categories

Resources