Wednesday , June 22 2022

Android Navigation Drawer Example using Fragments – Android Coding by DMTechnolab

The package The trap.Simplified coding.Navigation clearance;

Import Android..Bundle;

Import Android.Support.The design.Widget.Floating action button;

Import Android.Support.The design.Widget.the cafeteria;

Import Android.Support.v4.App.Denial;

Import Android.Support.v4.App.scent;

Import Android.Opinion.Opinion;

Import Android.Support.The design.Widget.Navigation view;

Import Android.Support.v4.Opinion.Graviticompat;

Import Android.Support.v4.Widget.Draw drawout;

Import Android.Support.v7.App.ActionBarDrawerToggle;

Import Android.Support.v7.App.AppCompatActivity;

Import Android.Support.v7.Widget.Toolbar;

Import Android.Opinion.Menu;

Import item;

public class Main activity Is spread AppCompatActivity

come into force Navigation view.OnNavigationItemSelectedListener {{


Protected Zero Go ahead()Bundle saveInstanceState) {{

Super.Go ahead()saveInstanceState);


Toolbar Toolbar = ()Toolbar) findViewById()R.Id.Toolbar);


Draw drawout The drawer = ()Draw drawout) findViewById()R.Id.The drawer);

Actionbrother toggle Toggle = New ActionBarDrawerToggle()

this, The drawer, Toolbar, R.Wire.Navigation_tractor_open, R.Wire.Navigation_tractor_close);

The drawer.setDrawerListener()Toggle);

Toggle.To crush());

Navigation view Navigation view = ()Navigation view) findViewById()R.Id.Boat_view);

Navigation view.setNavigationItemSelectedListener()this);

// Add this line to display menu 1 when the activity is loaded




public Zero onBackPressed()) {{

Draw drawout The drawer = ()Draw drawout) findViewById()R.Id.The drawer);

If ()The drawer.isDrawerOpen()Graviticompat.Start)) {{

The drawer.Closing()Gravity company.Start);

} other {{





public Boolean onCreateOptionsMenu()Menu Menu) {{

// inflate the menu; Adds the item to the action bar if it exists.

getMenuInflater()).To inflate()R.Menu.Important, Menu);

The return True;



public Boolean onOptionsItemSelected()menu item item) {{

// Handle action bar item click here. Action bar will be

// handles clicks on home / up buttons automatically, so for longer

// As you specify a basic activity in AndroidManifest.xml.

int Id = item.getItemId());

// noinspection SimpleifiableIfStatement

If ()Id == R.Id.Action_settings) {{

The return True;


The return Super.onOptionsItemSelected()item);


Private Zero displaySelectedScreen()int item ID) {{

// item to make the piece

Denial The piece = Invalid;

// Selecting the fragmented object that is selected

to switch ()item ID) {{

matter R.Id.nav_menu1:

The piece = New Menu 1());


matter R.Id.nav_menu2:

The piece = New Menu 2());


matter R.Id.nav_menu3:

The piece = New Menu 3());



// replace the piece

If ()The piece ! = Invalid) {{

scent Foot = getSupportFragmentManager()).Beginning());

Foot.To change()R.Id.content_frame, The piece);



Draw drawout The drawer = ()Draw drawout) findViewById()R.Id.The drawer);

The drawer.Closing()Graviticompat.Start);


@Suppress Warnings()“Statement)


public Boolean onNavigationItemSelected()menu item item) {{

// Calling methodSelectScreen and passing id of selected menu


// clear this method

The return True;



Source link

About dmtechnolab

Check Also

Simplified Coding

Android Hilt Tutorial – Injecting Dependencies with Hilt – Android Coding by DMTechnolab

You are welcome Android Hilt tutorial. I hope you all are aware of it Dependency …

Leave a Reply

Your email address will not be published. Required fields are marked *