Description for Bottom navigation part 2 in Android using Kotlin:

Bottom navigation
Step 1.  Add Framelayout in Layout File
Step 2. Create  fragment in android studio for your app
Step 3. How to use fragmentmanager to use fragment in your app

Load fragment in app on BottomNavigationView event 

Steps1. create new fragment->fragment blank of h fragment.kt and another of create aboutfragment.kt
Step2. fragment_home_xml-> attributes-> text-> I am  home fragment
 Step3. fragment_about_xml-> attributes-> text-> I am about fragment

Go to MainActivity.kt (code)

supportFragmentManager.begin Transaction ().add(R.id.root_container,HomeFragment()).commit()
Bottomview.setOnNavigationItemSelectedListener( 

/*Part one logic
Val msg= when(it.itemID)
{
R.id.about->”About Selected”
else ->”Home selected”
}
Toast.make text(this @MainActivity,msg,Toast.LENGTH_LONG).show() /*

Val fragment=when(it.itemId)

R.id.about->AboutFragment()
   else->HomeFragment ()
}

SupportFragmentManager.begin Transaction ().replace(R.id. root_container, fragment).commit()
True 
}
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *