I am using Navigation Component to navigate
Main Activity code here :
lateinit var appBarConfiguration: AppBarConfiguration
lateinit var navController: NavController
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Utils.setStatusBarGradiant(this)
setContentView(R.layout.activity_main)
supportActionBar?.setBackgroundDrawable(getDrawable(R.drawable.gradient_theme))
// bottom navigation
navController = findNavController(R.id.nav_host_fragment)
bottomNavigationView.setupWithNavController(navController)
//Navigation UP Button
appBarConfiguration = AppBarConfiguration(navController.graph, drawer_Layout)
//create arrow button
NavigationUI.setupActionBarWithNavController(this, navController, drawer_Layout)
//Drawer Navigation
NavigationUI.setupWithNavController(nav_view, navController)
}
// click on arrow button ( back to home fragment function)
override fun onSupportNavigateUp(): Boolean {
return NavigationUI.navigateUp(navController, appBarConfiguration)
}
Main Activity XML file here :
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawer_Layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<fragment
android:id="@+id/nav_host_fragment"
android:layout_width="match_parent"
android:layout_height="0dp"
android:name="androidx.navigation.fragment.NavHostFragment"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navGraph="@navigation/mobile_navigation"/>
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:labelVisibilityMode="labeled"
android:background="?android:attr/windowBackground"
app:itemIconTint="@drawable/newgradient"
app:itemTextColor="@drawable/newgradient"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/bottom_nav_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
app:menu="@menu/drawer_menu"
android:background="@color/drawerblack"
app:itemTextColor="@color/white"
app:itemIconTint="@color/white"
app:headerLayout="@layout/nav_header_main">
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="20dp"
android:orientation="vertical"
app:cardCornerRadius="10dp">
<ImageView
android:id="@+id/yt"
android:layout_width="match_parent"
android:layout_height="70dp"
android:gravity="center"
android:scaleType="centerCrop"/>
</androidx.cardview.widget.CardView>
</com.google.android.material.navigation.NavigationView>
</androidx.drawerlayout.widget.DrawerLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
This is the Navigation Drawer Menu Picture
My Question is : When I Click on Orders in Navigation Drawer Menu , I want to go to Order Fragment which is inside Main Activity