Disable the selection context menu in the pedestrian crossing (cordova)

I want to disable my own context menu that appears when you select any text, one that has the select all , copy , share and search buttons. However, I do not want to turn off the selection myself. Ideally, I would really like to expand the menu, but to be honest, I more than understand perfectly well just by turning it off. With text fields, etc. It tends to be relatively simple from the documentation I found, but I just can't figure out how to make this work with XWalkView / CordovaWebView . Maybe I was just looking for a completely wrong angle.

+5
source share
4 answers

I have a workaround.

There is a solution for WebView , but it does not work for XWalkView :

WebView Selection Bypass Menu

My gradle includes compile 'org.xwalk:xwalk_core_library:14.43.343.17'

My solution, the main idea of ​​the onAttachedToWindow method:

 public class XWalkWebView extends XWalkView { public XWalkWebView(Context context, AttributeSet attrs) { super(context, attrs); } private ActionMode.Callback mOriginalCallback; @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); try { View innerChild = ((ViewGroup) getChildAt(0)).getChildAt(0); Field contentViewField = innerChild.getClass().getDeclaredField("mContentView"); contentViewField.setAccessible(true); XWalkContentView xWalkContentView = (XWalkContentView) contentViewField.get(innerChild); Field contentViewCoreField = xWalkContentView.getClass().getSuperclass().getDeclaredField("mContentViewCore"); contentViewCoreField.setAccessible(true); ContentViewCore viewCore = (ContentViewCore) contentViewCoreField.get(xWalkContentView); viewCore.setContainerView(this); } catch (NoSuchFieldException | IllegalAccessException e) { e.printStackTrace(); } } @Override public ActionMode startActionMode(ActionMode.Callback callback) { mOriginalCallback = callback; ActionMode.Callback c = new // your callback... return super.startActionMode(c); } } 
+1
source

I will try the Warabei solution, but it does not work on 15.44.384.13. I improve the search for cross versions of ContentViewCore:

 public class XWalkWebView extends XWalkView { ... private Field getFields(Class clazz){ for(Field field:clazz.getDeclaredFields()){ if(ContentViewCore.class == field.getType()){ return field; } } clazz = clazz.getSuperclass(); if(clazz!=null && clazz!=Object.class){ Field field = getFields(clazz); if(field!=null)return field; } return null; } private void inject(View view){ Field field = getFields(view.getClass()); if(field!=null){ field.setAccessible(true); try { ContentViewCore viewCore = (ContentViewCore) field.get(view); viewCore.setContainerView(this); return; }catch(Exception e){ } } if(view instanceof ViewGroup){ ViewGroup viewGroup = (ViewGroup)view; int count = viewGroup.getChildCount(); for(int i = 0;i<count;i++){ inject(viewGroup.getChildAt(i)); } } } @Override protected void onAttachedToWindow() { super.onAttachedToWindow(); inject(this); } ... 

To disable the selection context menu:

 @Override public ActionMode startActionMode(ActionMode.Callback callback) { return new ActionMode() { @Override public void setTitle(CharSequence charSequence) { } @Override public void setTitle(int i) { } @Override public void setSubtitle(CharSequence charSequence) { } @Override public void setSubtitle(int i) { } @Override public void setCustomView(View view) { } @Override public void invalidate() { } @Override public void finish() { } @Override public Menu getMenu() { return null; } @Override public CharSequence getTitle() { return null; } @Override public CharSequence getSubtitle() { return null; } @Override public View getCustomView() { return null; } @Override public MenuInflater getMenuInflater() { return null; } }; } 
0
source

This is an old post, but I could not find another solution.

A simple workaround to turn off context settings in a crosswalk view.

  1. Go to your crosswalk project in res / menu / select_action_menu.xml
  2. Delete or comment on an item you don’t want to show
  3. Save, Build and Run
0
source

This CSS should prevent the context menu in Android and IOS, as indicated in the cordova template

 * { -webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */ } body { -webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */ -webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */ -webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */ } 
-2
source

Source: https://habr.com/ru/post/1205301/


All Articles