protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button popMenu = FindViewById<Button>(Resource.Id.popupMenuBtn); Button popWindow = FindViewById<Button>(Resource.Id.popupWindowBtn); popMenu.Click += delegate { PopupMenu menu = new PopupMenu (this, popMenu); // with Android 3 need to use MenuInfater to inflate the menu //menu.MenuInflater.Inflate (Resource.Menu.popup_menu, menu.Menu); // with Android 4 Inflate can be called directly on the menu menu.Inflate (Resource.Menu.popup_menu); menu.MenuItemClick += (s1, arg1) => { Console.WriteLine ("{0} selected", arg1.Item.TitleFormatted); }; // Android 4 now has the DismissEvent menu.DismissEvent += (s2, arg2) => { Console.WriteLine ("menu dismissed"); }; menu.Show (); }; popWindow.Click += delegate { LayoutInflater inflater = (LayoutInflater) this.GetSystemService(Context.LayoutInflaterService); PopupWindow pw = new PopupWindow(inflater.Inflate(Resource.Layout.popup_example, null, false),200,250, true); pw.ShowAtLocation(this.FindViewById(Resource.Id.main), GravityFlags.Center, 0, 0); Button closePopup = (Button)pw.ContentView.FindViewById(Resource.Id.closePopup); closePopup.Click += delegate { pw.Dismiss(); }; }; }
public override bool OnOptionsItemSelected(IMenuItem item) { if (item == _aboutUsMenu) { Display display = WindowManager.DefaultDisplay; Android.Util.DisplayMetrics metrics = new Android.Util.DisplayMetrics(); display.GetMetrics(metrics); int width = (int)Math.Min(display.Width * 0.8, 360 * metrics.Density); int height = (int)Math.Min(display.Height * 0.8, 480 * metrics.Density); PopupWindow aboutWindow = new PopupWindow(LayoutInflater.Inflate(Resource.Layout.about_us, null, false), width, height); TextView appVersionText = aboutWindow.ContentView.FindViewById<TextView>(Resource.Id.AboutUsVersionTextView); appVersionText.Text = String.Format("{0}: {1}", Resources.GetString(Resource.String.application_version), this.PackageManager.GetPackageInfo(PackageName, Android.Content.PM.PackageInfoFlags.Activities).VersionName); Button closeButton = aboutWindow.ContentView.FindViewById<Button>(Resource.Id.AboutUsCloseButton); closeButton.Click += delegate { aboutWindow.Dismiss(); }; TextView aboutUsNoteTextView = aboutWindow.ContentView.FindViewById<TextView>(Resource.Id.AboutUsModuleInfoTextView); //Emgu.CV.Util.VectorOfOclPlatformInfo oclInfo = Emgu.CV.OclInvoke.GetPlatformInfo(); String txt = String.Format("Has OpenCL: {0}", CvInvoke.HaveOpenCL); if (CvInvoke.HaveOpenCL) { txt = String.Format("{0}{1}Use OpenCL: {2}{3}{4}{5}", txt, System.Environment.NewLine, CvInvoke.UseOpenCL, System.Environment.NewLine, CvInvoke.OclGetPlatformsSummary(), System.Environment.NewLine); } txt = String.Format("{0}{1}Has Cuda: {2}", txt, System.Environment.NewLine, CudaInvoke.HasCuda); aboutUsNoteTextView.Text = txt; aboutWindow.ShowAtLocation(this.Window.DecorView, GravityFlags.Center, 0, 0); } else if (item == _settingsMenu) { Intent settingsIntent = new Intent(this, typeof(SettingActivity)); StartActivity(settingsIntent); } return base.OnOptionsItemSelected(item); }
private void Show() { if (cachedDataContext != null && DataContext == null) bindingContext.DataContext = cachedDataContext; popup = new PopupWindow( bindingContext.BindingInflate(templateId, null), ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent, true); popup.SetBackgroundDrawable(new BitmapDrawable()); // This is needed, see http://stackoverflow.com/a/3122696 popup.DismissEvent += delegate { HandleDismiss(); }; popup.AnimationStyle = Android.Resource.Style.AnimationTranslucent; popup.ShowAtLocation(this, GravityFlags.NoGravity, 0, 0); if (SoftInput) ShowSoftInput(); dissmissing = false; }