Android – Navigation Drawer

Android – Navigation Drawer

Navigation Drawer can provide the main navigation for an application, and it is hidden in the left edge. You can make it visible by swiping the screen from left to right, or by clicking the App icon(hamburger icon) at the left of the Application title The easiest way and the recommended one is to let Android Studio create one for you. You can do by right-clicking your app’s package name, then New > Activity > Navigation Drawer Activity. It will create 3 XML layout files, the main, the app_bar_main, and…

Android – Navigation Drawer Read More

Android Kotlin – Navigation and animation

Screenshot 20181219 112546

You can use animation when you use Navigation. It is to implement it. First, you need to create a new animation resource file. Right-click res folder, then click New and then New Android Resource File. You will see the following window. Specify the filename and choose Animation from the Resource type drop-down list. Click OK. Open the animation resource file and create an animation. The following is a simple fade-in animation. <set xmlns:android=”http://schemas.android.com/apk/res/android”> <alpha android:fromAlpha=”0.00″ android:toAlpha=”1.00″ android:duration=”@android:integer/config_longAnimTime”/></set> Now open the navigation layout and click on an action you want to have animation.…

Android Kotlin – Navigation and animation Read More

Android Kotlin – Navigation Block swiping navigation drawer

Screenshot 20181214 180741

There are times that you want the Navigation drawer not be available to the user, depending on which activity or fragment is active. With Navigation, you can do that by using addOnDestinationChangedListener and set the DrawerLockMode. Here is an example: private lateinit var drawerLayout: DrawerLayout override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) drawerLayout = findViewById(R.id.drawerLayout) val navController = findNavController(this,R.id.myNavHostFragment) navController.addOnDestinationChangedListener{navC:NavController, navD:NavDestination, _ -> if (navD.id == R.id.main_activity){ drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED) } else{ drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED) } } … … … } Enjoy! Android Kotlin – Navigation Block swiping navigation drawer

Android Kotlin – Navigation Block swiping navigation drawer Read More

Android Kotlin – Navigation and navigation drawer

Screenshot 20181213 184448

First, you need to add the material support library dependency at the Build.gradle(App) implementation “com.google.android.material:material:$supportlibVersion” Because we use Navigation, you need to add new destinations to the Navigation layout and specify an ID for every destination. Then you have to create a menu resource file. Right-click res click New and then Android resource file. Specify a file name and select Menu as the resource type. Click OK. Now edit the navigation_drawer_menu. Add the items you want the menu to have. Check the example below. Just remember the id of the item should be the same…

Android Kotlin – Navigation and navigation drawer Read More

Android Kotlin – Navigation and Passing data with safe args

Screenshot 20181210 123036

Open Build.gradle(Project) and add  in dependencies: classpath “android.arch.navigation:navigation-safe-args-gradle-plugin:$navigationVersion” then open Build.gradle(app) and add at the top: apply plugin: ‘androidx.navigation.safeargs’ Sync project and then select Rebuild Project from the Build Menu. This will generate code that contains object and builder classes for the actions with the sending and receiving destinations. More information here. Now open the navigation layout and select the destination that will receive the arguments. Click the small + at the right. Add the argument that you want to be received. Next, you need to edit the activity/fragment that will…

Android Kotlin – Navigation and Passing data with safe args Read More