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 Android.Opinion.menu item;
public class Main activity Is spread AppCompatActivity
come into force Navigation view.OnNavigationItemSelectedListener {{
@Override
Protected Zero Go ahead()Bundle saveInstanceState) {{
Super.Go ahead()saveInstanceState);
setContentView()R.Layout.activity_main);
Toolbar Toolbar = ()Toolbar) findViewById()R.Id.Toolbar);
setSupportActionBar()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
displaySelectedScreen()R.Id.nav_menu1);
}
@Override
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 {{
Super.onBackPressed());
}
}
@Override
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;
}
@Override
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());
break;
matter R.Id.nav_menu2:
The piece = New Menu 2());
break;
matter R.Id.nav_menu3:
The piece = New Menu 3());
break;
}
// replace the piece
If ()The piece ! = Invalid) {{
scent Foot = getSupportFragmentManager()).Beginning());
Foot.To change()R.Id.content_frame, The piece);
Foot.Committed());
}
Draw drawout The drawer = ()Draw drawout) findViewById()R.Id.The drawer);
The drawer.Closing()Graviticompat.Start);
}
@Suppress Warnings()“Statement)
@Override
public Boolean onNavigationItemSelected()menu item item) {{
// Calling methodSelectScreen and passing id of selected menu
displaySelectedScreen()item.getItemId()));
// clear this method
The return True;
}
}
Source link