ListpopupwindowListpopupwindow Brief Introduction
The Listpopupwindow minimum requirement is api11, in order to be compatible to 2.1, can be implemented using the included in the support V7 package.
In effect, Listpopupwindow is a popup-level listview, which is more suitable for implementing a custom drop-down menu and a custom drop-down selection list.
Use of ListpopupwindowCustom styles
An example:
<style name= "V7. Listpopupwindowstyle "parent=" @style/widget.appcompat.listpopupwindow "> <item name=" android:popupbackground > #404040 </item>//pop-up background <item name= "Android:dropdownverticaloffset" >0dip</item> <item Nam E= "Android:dropdownhorizontaloffset" >0dip</item>//horizontal and vertical displacement <item name= "Android:dropdownwidth" > Match_parent</item>//This effect is not very </style><style name= "V7. Dropdownlistviewstyle "parent=" @style/widget.appcompat.listview.dropdown "> <item name=" android:listSelector "> @drawable/list_selector</item>//<item name=" Android:divider "> #242424 </item> <item name= "Android:dividerheight" >1px</item> ...//other list style tyle>apptheme are topics that apply to activity Listpopupwindowstyle The theme style Dropdownlistviewstyle corresponding to the pop-up layer corresponds to the theme style of the included list, consistent with the custom style of the normal ListView <style name= "V7. Listpopupwindow "parent=" Apptheme "> <item name=" Listpopupwindowstyle "> @style/v7. Listpopupwindowstyle</item> <itEM name= "Dropdownlistviewstyle" > @style/v7. Dropdownlistviewstyle</item></style>
Code calls
Implement the pop-up menu in the top right corner, using the same way as Popupwindow:
Listpopupwindow Listpopupwindow = new Listpopupwindow (this); Listpopupwindow.setanchorview (view); Listpopupwindow.setwidth (300); If you do not set the width, the default is to take the width of anchorview, generally not the result we want Listpopupwindow.setmodal (true); is modal, affecting the processing of the Back button Listpopupwindow.setadapter (new arrayadapter<string> (This, r.layout.apt_v7_list_popup_ window, R.ID.APT_V7_TV, new string[]{ "initiate group chat", "Add Friends", "sweep", "Feedback"}); Listpopupwindow.show ();
Comparison with the Popmenu
- Popmenu is difficult to customize, Listpopupwindow is more customizable
- Listpopupwindow Not Adaptive width
- The Popmenu is a menu-oriented core that allows for more convenient disabling/opening functions
A scheme to let Listpopupwindow adaptive width, set adapter, detect the maximum width of each row, and then to set the width of Listpopupwindow, pros and cons, their own choice.
Other ways to implement the menu:
Popmenu
Popupwindow + Custom Contentview
In-page view + custom touch events and key event handling
Demo
Demo
Android Share Q Group: 315658668
"Android" Listpopupwindow