Last active
August 21, 2020 16:40
-
-
Save ebubekirsezer/2b8b97360debee37ffab9190f1554416 to your computer and use it in GitHub Desktop.
KotlinNavigationDrawer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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" | |
xmlns:tools="http://schemas.android.com/tools"> | |
<androidx.drawerlayout.widget.DrawerLayout | |
android:id="@+id/drawerLayout" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical"> | |
<fragment | |
android:id="@+id/myNavigationHostFragment" | |
android:name="androidx.navigation.fragment.NavHostFragment" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
app:defaultNavHost="true" | |
app:navGraph="@navigation/navigation" /> | |
</LinearLayout> | |
<com.google.android.material.navigation.NavigationView | |
android:id="@+id/navView" | |
android:layout_width="wrap_content" | |
android:layout_height="match_parent" | |
android:layout_gravity="start" | |
app:menu="@menu/nav_drawer_menu" /> | |
</androidx.drawerlayout.widget.DrawerLayout> | |
</layout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dataBinding{ | |
enabled = true | |
} | |
implementation 'androidx.navigation:navigation-fragment-ktx:2.3.0' | |
implementation 'androidx.navigation:navigation-ui-ktx:2.3.0' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
lateinit var binding: ActivityMainBinding | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
binding = DataBindingUtil.setContentView(this,R.layout.activity_main) | |
setupNavigation() | |
} | |
private fun setupNavigation(){ | |
val navController = findNavController(R.id.myNavigationHostFragment) | |
setupActionBarWithNavController(navController,binding.drawerLayout) | |
binding.navView.setupWithNavController(navController) | |
} | |
override fun onSupportNavigateUp(): Boolean { | |
return NavigationUI.navigateUp(findNavController(R.id.myNavigationHostFragment),binding.drawerLayout) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment