In an android webview is it possible to add an menu item in the webview's default contextual action bar menu.This contextual action bar appears when some webview page contents are selected.The menu item should appear above share in the menu items list.
Asked
Active
Viewed 3,442 times
2
-
2Hi matt,i am a newbie to android.i tried to find some tutorial on this but didnt find any.There are ways to add new contextual action bar but i need to add to the existing one.Any help on this would be greatful – Vinay Revankar Oct 09 '12 at 04:49
-
actually there is a way, please refer to first answer http://stackoverflow.com/questions/22336903/override-onlongtouch-in-a-webview-but-keep-text-selection#2 – Defuera Jul 04 '14 at 10:07
3 Answers
2
In an android webview is it possible to add an menu item in the webview's default contextual action bar menu.
No, sorry. Few Android widgets allow you to contribute to their action modes -- EditText
does, and that is the only one that I can think of.

CommonsWare
- 986,068
- 189
- 2,389
- 2,491
1
Everything you want to know about manipulating contextual actionbar menus is here. You can simply inflate a menu for the contextual action-mode appearance.
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
// Inflate a menu resource providing context menu items
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.context_menu, menu);
return true;
}

C--
- 16,393
- 6
- 53
- 60
0
If you are looking for tutorials, here are some resources you can use:
https://developer.android.com/guide/topics/ui/menus.html#context-menu
http://mobile.tutsplus.com/tutorials/android/android-sdk-context-menus/
Basically, you can create a layout and inflate it on clicking your button:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/menu_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="10dip" >
<TextView
android:id="@+id/menuItem1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/menu1" />
<TextView
android:id="@+id/menuItem2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/menu2" />
<TextView
android:id="@+id/menuItem3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:text="@string/menu3" />
</LinearLayout>
and in your showPopup() method you can do something like:
public void showPopup(View v) {
LayoutInflater inflater = (LayoutInflater) MainActivity.this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
PopupWindow pw = new PopupWindow(inflater.inflate(
R.layout.container, null, false), 400, 500, true);
pw.showAtLocation(findViewById(R.id.menu_layout), Gravity.CENTER, 0,
0);
}

Anup Cowkur
- 20,443
- 6
- 51
- 84