"Android" Listpopupwindow

Source: Internet
Author: User

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
    1. Popmenu is difficult to customize, Listpopupwindow is more customizable
    2. Listpopupwindow Not Adaptive width
    3. 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:

    1. Popmenu

    2. Popupwindow + Custom Contentview

    3. In-page view + custom touch events and key event handling

Demo

Demo

Android Share Q Group: 315658668

"Android" Listpopupwindow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.