相关疑难解决方法(0)

覆盖Android中文本选择(在WebView中)的默认上下文操作栏

我想覆盖现有的默认上下文操作栏(CAB)进行文本选择.我的意思是,当我在webview上选择一些文本时,我想用自己的按钮显示我自己的CAB.我尝试使用Android文档实现CAB.OnLongClickListener不捕获Web视图中的文本选择事件.捕获文本选择的事件是什么?是否可以隐藏默认CAB并在文本选择上显示我的CAB?

childWebView.setOnLongClickListener(new OnLongClickListener() {
        @Override
     // Called when the user long-clicks on someView
        public boolean onLongClick(View view) {
            if (mActionMode != null) {
                return false;
            }

            // Start the CAB using the ActionMode.Callback defined above
            mActionMode = startActionMode(mActionModeCallback);
            view.setSelected(true);
            return true;
        }
    });
Run Code Online (Sandbox Code Playgroud)

android android-webview contextual-action-bar

27
推荐指数
1
解决办法
8239
查看次数

使用自定义上下文操作栏进行WebView文本选择

我使用了Google本教程中的指南来制作我自己的上下文操作栏.

private ActionMode.Callback mActionModeCallback = new ActionMode.Callback() {

    // Called when the action mode is created; startActionMode() was called
    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
        // Inflate a menu resource providing context menu items
        MenuInflater inflater = mode.getMenuInflater();
        inflater.inflate(R.menu.annotation_menu, menu);
        return true;
    }

    // Called each time the action mode is shown.
    // Always called after onCreateActionMode, but
    // may be called multiple times if the mode is invalidated.
    @Override
    public boolean onPrepareActionMode(ActionMode mode, …
Run Code Online (Sandbox Code Playgroud)

android webview touch-event

20
推荐指数
1
解决办法
2万
查看次数

如何覆盖android中的Web视图文本选择菜单

基本的android的网络文本选择菜单如下图所示.它有复制,共享,全选,网络搜索等选项.

在此输入图像描述

我想过度使用这个菜单并希望它们作为我自己的菜单列表,如"标记颜色","标记为imp"等.我查看有关堆栈溢出的上下文菜单的大部分问题.大多数问题与上下文菜单有关,但没有按预期给出结果.我想要下面的图像菜单

在此输入图像描述

当我执行选择android监视器显示一些视图创建窗体viewRoot喜欢

D/ViewRootImpl: #1 mView = android.widget.PopupWindow$PopupDecorView{648898f V.E...... ......I. 0,0-0,0}
D/ViewRootImpl: #1 mView = android.widget.PopupWindow$PopupDecorView{a66541c V.E...... ......I. 0,0-0,0}
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
D/ViewRootImpl: MSG_RESIZED_REPORT: ci=Rect(0, 0 - 0, 0) vi=Rect(0, 0 - 0, 0) or=1
Run Code Online (Sandbox Code Playgroud)

如何实现这样的实现?

我也浏览了https://github.com/naoak/WebViewMarker但没有得到正确的结果.

我做了什么呢?

我扩展了Android的WebView,我想支持最小的SDK 19.当我执行长按时我得到了长按事件,但我无法获得这样的菜单创建api调用.

android webview android-menu

17
推荐指数
2
解决办法
5259
查看次数

Android:如何从webview中选择文本

我希望允许用户从webview中选择一些文本,它需要作为文本消息发送.请找到选择文本并复制到剪贴板并从剪贴板中提取的方法.我看到很多例子,但没有任何帮助我真的...... TIA


使用@ orangmoney52链接中提供的代码进行编辑.以下更改

getmethod的第二个参数和invoke方法的第二个参数.如果我给null那里会有警告......哪一个是正确的?

 public void selectAndCopyText() {
     try {
         Method m = WebView.class.getMethod("emulateShiftHeld", Boolean.TYPE); 
            m.invoke(BookView.mWebView, false); 
        } catch (Exception e) {
            e.printStackTrace();
            // fallback
            KeyEvent shiftPressEvent = new KeyEvent(0,0,
                 KeyEvent.ACTION_DOWN,KeyEvent.KEYCODE_SHIFT_LEFT,0,0);
            shiftPressEvent.dispatch(this);
        }

}
Run Code Online (Sandbox Code Playgroud)

得到此错误:

 05-26 16:41:01.121: WARN/System.err(1096): java.lang.NoSuchMethodException: emulateShiftHeld  
Run Code Online (Sandbox Code Playgroud)

android copy-paste webview

14
推荐指数
3
解决办法
3万
查看次数

在webview的文本选择上打开自定义对话框

我在webview中实现了文本选择代码.它没有任何问题,工作得非常好.但我想打开自定义对话框而不是默认对话框.我使用它的链接在下面

如何覆盖android webview os 4.1+的默认文本选择?

但它不适用于自定义对话框.

找到下面的代码

public class CustomWebView extends WebView {
private Context context;

private ActionMode mActionMode;
private ActionMode.Callback mSelectActionModeCallback;
private GestureDetector mDetector;

public CustomWebView(Context context) {
    super(context);
    this.context = context;
    WebSettings webviewSettings = getSettings();
    webviewSettings.setJavaScriptEnabled(true);
    // add JavaScript interface for copy
    WebAppInterface webAppInterface = new WebAppInterface(context);
    addJavascriptInterface(webAppInterface, "JSInterface");
}

public CustomWebView(Context context, AttributeSet attrs) {
    super(context, attrs);
    this.context = context;
}

public CustomWebView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.context = context;
}

// …
Run Code Online (Sandbox Code Playgroud)

android dialog textselection webview contextual-action-bar

10
推荐指数
0
解决办法
618
查看次数

如何覆盖webview的文本选择上下文菜单?

我有一个要求,比如当我长按网页视图中的文字时点击长按,我应该设置我的自定义上下文菜单项而不是"选择","全选","网页搜索".

请帮我.

在此输入图像描述

想要覆盖这些默认的"全选","复制","分享","网络搜索".在这个地方想要我的自定义菜单.

android contextmenu webview

6
推荐指数
1
解决办法
4951
查看次数