android - How to add a Contextual Action Bar to a Dialog -


i have several cases gridview within dialogfragment needs contextual menu. project supports api 8+, i'm using appcompat support library. far i've tried calling activity.startsupportactionmode() on underlying actionbaractivity, starts contextual actionbar/actionmode underneath dialog. i'm looking alternative common-but-hacky (and high-overhead) method of using activity themed dialog.

poking around in source both framework , appcompat support library, get:

for api 11+ standard framework:

dialog dialog; actionmode.callback actionmode;  window window = dialog.getwindow(); view toplevel = window.getdecorview(); if (toplevel == null) { return; }  toplevel.startactionmode (actionmode); 

for appcompat support library:

window window = dialog.getwindow(); view toplevel = window.getdecorview(); if (toplevel == null) { return; }  android.view.actionmode.callback frameworkactionmode =      new callbackwrapper (context, supportactionmode); toplevel.startactionmode (frameworkactionmode); 

note if you're using dialogfragment, you'll need reference getdialog(), which may null, depending on in dialogfragment lifecycle.

as of revision 19.1.0 (mar 2014), appcompat support library includes internal class (android.support.v7.internal.view.actionmodewrapper.callbackwrapper) can used wrap support-library actionmode.callback in framework callback. if prefer not rely on internal classes, can roll own wrapper.


Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -