![]() ![]()
In the Navigation Menu, there are some social links like Facebook, G+, Twitter, YouTube, and Github. I will handle the menu click items in the following lines of code, public boolean onNavigationItemSelected(MenuItem item) Navigation Menu item - WebViewFragment ![]() I initialized the NavigationView using the following couple of lines, NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view) tNavigationItemSelectedListener(this) So now the NaviginationMenu is completed, now I will link this menu item clicks to its related fragment. ANDROID NAVIGATION DRAWER SET ICON ANDROIDThe social network icons I used are from the other icons are default android icons. ANDROID NAVIGATION DRAWER SET ICON DOWNLOADIn the above screenshots, you can see an icon beside each menu item, that can be set using the android icon attribute these icons are either android default images or you can download any icon of your wish and use them. I also gave a title to the sub menu as 'Social'. Item which is the single menu item, we can divide/separate the menu by creating an another menu as the sub-child of item element. menu which is the root element and it can have sub child's/sub elements like item and group. If you look at the above code, I created a menu using menu, item, and group. ANDROID NAVIGATION DRAWER SET ICON CODEOpen the activity_main_drawer.xml file and place the following code in it. In the above snippet in the last line which says that the menu for this is located at menu directory in the res folder. We are going to use drawerContent prop of Drawer.Navigator to set our. It is hidden most of the time, but is revealed when the user swipes a finger from the left edge of the screen or, while at the top level of the app, the user touches the app icon in the action bar. In the custom Sidebar, we will have a profile image and additional options with the icon. The drawer appears when the user touches the drawer icon in the app bar or when the user swipes a finger. Add 4.widget.DrawerLayout as root view of activity layout. If you open activity_main.xml file at app/res/layout directory, you can see the code for NavigationMenu. The navigation drawer is a panel that displays the app’s main navigation options on the left edge of the screen. Introduction The navigation drawer is a UI panel that shows your app’s main navigation menu. For creating a navigation drawer, first we need to declare the drawer layout in your main activity where you want to show the navigation drawer. First, I will finish the navigation menu layout. I will go step by step and tell you about the application we are going to build. Here I will use that and extend it to leverage the code Android Studio gave us by default :D Navigation Menu Basically, it has the navigation menu, icons, header and handling the menu item clicks and all that stuff. So after Android Studio does its thing and eventually show you ‘Gradle build finished’ (:P just kidding, if you have a good configuration, everything will load fine), you can see some layout files and an activity file (MainActivity.java) with some code written in it. HomeFragment is assigned as the default fragment at the end of onCreate method.Navigation Drawer Example. Public class SettingsFragment extends Fragment In this code the FloatingActionButton related code is removed since the button is moved to the HomeFragment. Īfter the modification, the SettingsFragment.java should look like this: package Modify it using any desired icon and content. Layout/nav_header_main.xml is the layout which defines the header part of Navigation Drawer. ![]() This layout is used to decorate the fragments using an overlaying ActionBar. Modify the layout/app_bar_main.xml as shown below. Modify the content of the layout/fragment_home.xml as shown below. 5 Answers Sorted by: 19 Add the following line to appsrcmainresvaluesdimens.xml file. ![]()
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |