MainActivity.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. using System;
  2. using Android.App;
  3. using Android.OS;
  4. using Android.Runtime;
  5. using Android.Views;
  6. using AndroidX.AppCompat.Widget;
  7. using AndroidX.AppCompat.App;
  8. using Google.Android.Material.FloatingActionButton;
  9. using Google.Android.Material.Snackbar;
  10. namespace App_demo
  11. {
  12. [Activity(Label = "@string/app_name", Theme = "@style/AppTheme.NoActionBar", MainLauncher = true)]
  13. public class MainActivity : AppCompatActivity
  14. {
  15. protected override void OnCreate(Bundle savedInstanceState)
  16. {
  17. base.OnCreate(savedInstanceState);
  18. Xamarin.Essentials.Platform.Init(this, savedInstanceState);
  19. SetContentView(Resource.Layout.activity_main);
  20. Toolbar toolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
  21. SetSupportActionBar(toolbar);
  22. FloatingActionButton fab = FindViewById<FloatingActionButton>(Resource.Id.fab);
  23. fab.Click += FabOnClick;
  24. }
  25. public override bool OnCreateOptionsMenu(IMenu menu)
  26. {
  27. MenuInflater.Inflate(Resource.Menu.menu_main, menu);
  28. return true;
  29. }
  30. public override bool OnOptionsItemSelected(IMenuItem item)
  31. {
  32. int id = item.ItemId;
  33. if (id == Resource.Id.action_settings)
  34. {
  35. return true;
  36. }
  37. return base.OnOptionsItemSelected(item);
  38. }
  39. private void FabOnClick(object sender, EventArgs eventArgs)
  40. {
  41. View view = (View) sender;
  42. Snackbar.Make(view, "Replace with your own action", Snackbar.LengthLong)
  43. .SetAction("Action", (View.IOnClickListener)null).Show();
  44. }
  45. public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults)
  46. {
  47. Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);
  48. base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
  49. }
  50. }
  51. }