Skip to content

Instantly share code, notes, and snippets.

Avatar
:octocat:
Subscribe to my newsletter: wajahatkarim.com/subscribe

Wajahat Karim wajahatkarim3

:octocat:
Subscribe to my newsletter: wajahatkarim.com/subscribe
View GitHub Profile
View MainActivity.kt
fun showBottomNavigation()
{
bottomNavView.visibility = View.VISIBLE
}
fun hideBottomNavigation()
{
bottomNavView.visibility = View.GONE
}
View NotificationFragment.kt
class NotificationsFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_notifications, container, false)
}
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
setupViews()
View bottom_nav_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/bottom_nav_graph.xml"
app:startDestination="@id/homeFragment">
<fragment
android:id="@+id/homeFragment"
android:name="com.wajahatkarim3.bottomnavigationdemo.HomeFragment"
View search_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:title="Search"
android:icon="@drawable/ic_baseline_search_24"
app:showAsAction="always"
android:iconTint="@color/colorWhite"/>
</menu>
View SearchFragment.kt
override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) {
inflater.inflate(R.menu.search_menu, menu)
}
View SearchFragment.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setHasOptionsMenu(true)
}
View MainActivity.kt
fun setupViews()
{
// Finding the Navigation Controller
var navController = findNavController(R.id.fragNavHost)
// Setting Navigation Controller with the BottomNavigationView
bottomNavView.setupWithNavController(navController)
// Setting Up ActionBar with Navigation Controller
// Pass the IDs of top-level destinations in AppBarConfiguration
View MainActivity.kt
fun setupViews()
{
// Finding the Navigation Controller
var navController = findNavController(R.id.fragNavHost)
// Setting Navigation Controller with the BottomNavigationView
bottomNavView.setupWithNavController(navController)
// Setting Up ActionBar with Navigation Controller
setupActionBarWithNavController(navController)
View MainActivity.kt
fun setupViews()
{
// Finding the Navigation Controller
var navController = findNavController(R.id.fragNavHost)
// Setting Navigation Controller with the BottomNavigationView
bottomNavView.setupWithNavController(navController)
}
@wajahatkarim3
wajahatkarim3 / bottom_nav_graph.xml
Created Jan 12, 2020
The navigation with bottom 4 screens
View bottom_nav_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/bottom_nav_graph.xml"
app:startDestination="@id/homeFragment2">
<fragment
android:id="@+id/homeFragment2"
android:name="com.wajahatkarim3.bottomnavigationdemo.HomeFragment"
You can’t perform that action at this time.