Android bits and pieces: popups

November 10th, 2014

One of the more useful things that was “graduated” from the internal package in the latest drop of support libraries is ListPopupWindow.

No more need to try and emulate the look and feel of a popup window with a custom styled and positioned dialog for older platform releases.

Use R.layout.abc_popup_menu_item_layout for platform-consistent appearance (text style, margins, regular / ripple highlights) in your list adapter. Then set it with ListPopupWindow.setAdapter, optionally register a dismiss listener (note how the overflow dots for the “active” popup are darker), set anchor view for properly positioning the popup, compute the content width based on the content of your list, optionally mark it as modal so that it can be dismissed by tapping outside and don’t forget to call show().