How to remove items from contextual action bar android -
i want remove copy, select all , find android contextual action bar , add custom menu items.

this appearing while selecting text on webview. trying add text highlights on webview using js.
in order accomplish want, need create entirely new contextual action bar. done through creating custom actionmode. within webview, create nested class implements actionmode.callback. can use template:
public class customwebview extends webview { private actionmode.callback mactionmodecallback; @override public actionmode startactionmode(actionmode mode) { // block directly webview source code. viewparent parent = getparent(); if (parent == null) { return null; } mactionmodecallback = new customactionmodecallback(); return parent.startactionmodeforchild(this, mactionmodecallback); } private class customactionmodecallback implements actionmode.callback { // called when action mode created; startactionmode() called @override public boolean oncreateactionmode(actionmode mode, menu menu) { // inflate menu resource providing context menu items menuinflater inflater = mode.getmenuinflater(); inflater.inflate(r.menu.context_menu, menu); return true; } // called each time action mode shown. // called after oncreateactionmode, // may called multiple times if mode invalidated. @override public boolean onprepareactionmode(actionmode mode, menu menu) { // method called when selection handlebars moved. return false; // return false if nothing done } // called when user selects contextual menu item @override public boolean onactionitemclicked(actionmode mode, menuitem item) { switch (item.getitemid()) { case r.id.menu_button_1: // stuff break; case r.id.menu_button_2: // stuff break; default: // did not handle action, return false // if have implemented case every button, // block should never called. return false; } // if want close cab after // picking action, call mode.finish(). // if want cab persist until user clears selection // or clicks "done" button, return true. mode.finish(); // action picked, close cab return true; } // called when user exits action mode @override public void ondestroyactionmode(actionmode mode) { mode = null; } } } sure define menu in xml resources. here example go above template:
<!-- context_menu.xml --> <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/menu_button_1" android:icon="@android:drawable/menu_button_1" android:showasaction="always" android:title="@string/menu_button_1"> </item> <item android:id="@+id/menu_button_2" android:icon="@drawable/menu_button_2" android:showasaction="ifroom" android:title="@string/menu_button_2"> </item> </menu> noticed did not explicitly state want replace share , web search. unfortunately, method require implement functionality on own. however, can dig source code (i start in
actionmode.java) functions. implement new case in customactionmodecallback.onactionitemclicked (where handle button events), copy/paste functionality source, , add corresponding button in xml file. can use native icon functions: android:icon="@android:drawable/[name_of_desired_icon] for reference, information android developers website.
http://developer.android.com/guide/topics/ui/menus.html#cab
Comments
Post a Comment