android - Custom PopupMenu (layout) -
I'm trying to upgrade my popup menu so that it can come up with icons and custom styles.
I have a new layout for this
& lt ;? Xml version = "1.0" encoding = "UTF-8"? & Gt; & Lt; RelativeLayout Android: layout_width = "wrap_content" Android: layout_height = "wrap_content" xmlns: Android = "http://schemas.android.com/apk/res/android" & gt; & Lt; Android: Android: Android: Android: "Drawable / Share" Android: Padding Lift = "10.0 Dip" Android: Padding Right = "10.0 Dip" Android: Layout_width = "Wrap-content" Android: Layout_Hight = "50.0 Dip "Android: onClick =" Share "& gt; Android: text = "@ string / share" Android: drawableLeft = "@ drawable / share_button" Android: Android: Android: Android: DrawablePadding = "10.0dip" Android: layout_centerVertical = "true" /> & Lt; / RelativeLayout & gt; & Lt; Android: Android: Android: Android: "Drawable / Share" Android: Padding Lift = "10.0 DP" Android: Padding Right = "10.0 Dip" Android: Layout_With = "Wrap-content" Android: Layout_Hight = "50.0 Dip "android: layout_bel =" @ + id / layout_share "Android: onClick =" share "& gt; Android: text = "@ string / share" Android: drawableLeft = /> & Lt; / RelativeLayout & gt; & Lt; / RelativeLayout & gt; I want the popup menu to be customized as this image (such as this layout)
A is for display and there is no good way to actually customize the appearance of the menu item if you have something Want more flexible, so your answer is
Private Static Last String Title = "Title"; Private static last string icon = "icon"; Private listing & lt; Hashmap & lt; String, Object & gt; & Gt; Data = new arreelist & lt; Hashmap & lt; String, Object & gt; & Gt; (); // To add items to this list, use it in the list: PopPoint will use Private Zero Admit (String title, Ink iconRourceSource ID) {Hashmap & lt; String, Object & gt; Map = new hashmop & lt; String, Object & gt; (); Map.put (TITLE, title); Map.put (ICON, IconRSOSID); Data.add (map); } // Call it when you want to show the list popup, private private show zero list menu (see anchor) {ListPopupWindow popupWindow = new ListPopupWindow (this); ListAdapter adapter = New SimpleAdapter (this, data, android.r.layout.activity_list_item, // you may want to use your own cool layout new string [], {TITLE, ICON}, // it's just such keys The data that uses the new int [] (android.R.id.text1, android.R.id.icon}); // Popup to map the data to view ID Window.setAnchorView (anchor); PopupWindow.setAdapter (adapter); popupWindow.setWidth (400); // Note: Do not use pixels, use a slow resource popup. Window.setOnItemClickListener (myListener); // When a list Item popup is chosen if callback window.show ();}
Comments
Post a Comment