Guest User

Untitled

a guest
Dec 12th, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. popup = new PopupMenu(this, _showMore, GravityFlags.Top);
  2.  
  3. popup.MenuInflater.Inflate(Resource.Menu.showMoreMenu, popup.Menu);
  4. if (!string.IsNullOrEmpty(someValue))
  5. {
  6. popup.Menu.FindItem(Resource.Id.ABC1).SetVisible(false);
  7. }
  8.  
  9. popup.MenuItemClick += Popup_MenuItemClick;
  10. popup.Show();
  11.  
  12. PopupWindow popupWindow = new PopupWindow(this); // inflet your layout or diynamic add view
  13.  
  14. LayoutInflater inflater = (LayoutInflater)GetSystemService(Context.LayoutInflaterService);
  15. View view = inflater.Inflate(Resource.Layout.TestLayout, null, false);
  16.  
  17. TextView abc1 = (TextView)view.FindViewById(Resource.Id.abc1);
  18. TextView abc2 = (TextView)view.FindViewById(Resource.Id.abc2);
  19. TextView abc3 = (TextView)view.FindViewById(Resource.Id.abc3);
  20. abc1.Click += abc1_Click;
  21. abc2.Click += abc2_Click;
  22. if (!string.IsNullOrEmpty(somecondition))
  23. {
  24. abc1.Visibility = ViewStates.Gone;
  25. }
  26. else
  27. {
  28. abc2.Visibility = ViewStates.Gone;
  29. }
  30.  
  31. popupWindow.Focusable = (true);
  32. popupWindow.Width = (WindowManagerLayoutParams.WrapContent);
  33. popupWindow.Height = (WindowManagerLayoutParams.WrapContent);
  34. popupWindow.ContentView = (view);
  35. popupWindow.SetBackgroundDrawable(new ColorDrawable(Color.Transparent));
  36.  
  37. /*
  38. //tried
  39. var tttt= (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, Resource.Dimension._15sdp, Resources.DisplayMetrics);
  40.  
  41. //tried
  42. int test=(int)(Resource.Dimension._15sdp * Resources.DisplayMetrics.Density);
  43.  
  44. //tried
  45. float scale = Resources.DisplayMetrics.Density;
  46. test= (int)(Resource.Dimension._15sdp * scale + 0.5f);
  47.  
  48. //tried
  49. var dp = Resource.Dimension._15sdp;
  50. int pixel = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, dp, Resources.DisplayMetrics);
  51. */
  52.  
  53. popupWindow.ShowAsDropDown(_showMore, -220, -570); <-- fixed offset which works for 3 options
Add Comment
Please, Sign In to add comment