protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); SetContentView(Resource.Layout.activity_main); Android.Support.V7.Widget.Toolbar toolbar = FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); SetSupportActionBar(toolbar); FloatingActionButton fab = FindViewById <FloatingActionButton>(Resource.Id.fab); fab.Click += FabOnClick; DrawerLayout drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, Resource.String.navigation_drawer_open, Resource.String.navigation_drawer_close); drawer.AddDrawerListener(toggle); toggle.SyncState(); NavigationView navigationView = FindViewById <NavigationView>(Resource.Id.nav_view); navigationView.SetNavigationItemSelectedListener(this); //este metodo inicia un fragement cuando se abre la aplicacion if (savedInstanceState == null) { navigationView.SetCheckedItem(Resource.Id.nav_camera); var prueba2 = Fragment2.NewInstance(); FragmentManager.BeginTransaction().Replace(Resource.Id.contenedor, prueba2).Commit(); } }
void LoadFragment(int id) { Fragment fragment = null; switch (id) { case Resource.Id.action_home: fragment = Fragment1.NewInstance(); break; case Resource.Id.action_profile: fragment = Fragment2.NewInstance(); break; case Resource.Id.action_messages: fragment = Fragment3.NewInstance(); break; case Resource.Id.action_settings: fragment = Fragment4.NewInstance(); break; default: break; } if (fragment == null) { return; } FragmentManager.BeginTransaction() .Replace(Resource.Id.fragmentContainer, fragment) .Commit(); }
public bool OnNavigationItemSelected(IMenuItem item) { int id = item.ItemId; Fragment fragment = null; // if (id == null) //{ // Toast.MakeText(this,"Hora Ramces Maradiaga",ToastLength.Long).Show(); //} if (id == Resource.Id.nav_camera) { // Handle the camera action //FragmentTransaction ft = FragmentManager.BeginTransaction(); //Fragment1 f1 = new Fragment1(); //ft.Replace(Resource.Id.drawer_layout, f1); //ft.AddToBackStack(null); //ft.Commit(); var prueba = Fragment1.NewInstance(); //FragmentManager.BeginTransaction().Replace( Android.Resource.Id.Content,prueba).Commit(); FragmentManager.BeginTransaction().Replace(Resource.Id.contenedor, prueba).Commit(); } else if (id == Resource.Id.nav_gallery) { var prueba2 = Fragment2.NewInstance(); //FragmentManager.BeginTransaction().Replace( Android.Resource.Id.Content,prueba).Commit(); FragmentManager.BeginTransaction().Replace(Resource.Id.contenedor, prueba2).Commit(); } else if (id == Resource.Id.nav_slideshow) { } else if (id == Resource.Id.nav_manage) { } else if (id == Resource.Id.nav_share) { } else if (id == Resource.Id.nav_send) { } DrawerLayout drawer = FindViewById <DrawerLayout>(Resource.Id.drawer_layout); drawer.CloseDrawer(GravityCompat.Start); return(true); }