android - 在 android 的 webview 中突出显示选定的文本

标签 android webview

我是 android 中 webview 的新手。我正在开发应用程序,我想在 WebView 中标记选定的文本。

image from tab

在这里,我想删除右侧菜单并更改“完成”菜单的文本,然后单击“完成”后,我想在 WebView 中用颜色标记文本(突出显示文本)。

任何人都可以有任何想法吗?

请回复。等待有值(value)的回复。

最佳答案

我不知道如何控制选择上下文操作栏。但您可以阻止它显示并将其替换为您自己的版本。首先,创建一个扩展WebView的HighlightWebView类,并包含此覆盖:

@Override
public android.view.ActionMode startActionMode(android.view.ActionMode.Callback callback) {
    // this will start a new, custom Contextual Action Mode, in which you can control
    // the menu options available.
    highlightActivity.startActionMode(highlighActionModeCallback);

    // this is to prevent the native text selection ActionMode
    return null;
}

您还需要创建HighlightActionModeCallback 类。这是实现 ActionMode.Callback 的类的一个非常基本的版本:

public class HighlightActionModeCallBack implements ActionMode.Callback {

    @Override
    public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onCreateActionMode(ActionMode mode, Menu menu) {
        // TODO Auto-generated method stub
        mode.getMenuInflater().inflate(R.menu.highlight_menu, menu);
        return true;
    }

    @Override
    public void onDestroyActionMode(ActionMode mode) {
        // TODO Auto-generated method stub
    }

    @Override
    public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
        // TODO Auto-generated method stub
        return false;
    }

} 

您还需要在 Google 上搜索“上下文操作模式”和/或“上下文操作栏”以获取更多信息。

关于android - 在 android 的 webview 中突出显示选定的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21038727/

相关文章:

android - CREATE VIEW of UNION 两个表,合并行

java - 如何居中裁剪线性布局的背景图像?

java - Context.startForegroundService() 然后没有调用 Service.startForeground() 问题

Android 在 pinterest 中通过 facebook 登录在 webview 中不起作用

java - 使用表单条目填充电子邮件 Eclipse Android

Android Intent - 将 uri 传递给相机

android - 在 Android 应用中静音 webview

android - IBM Worklight - 如何在 Android 中启用 WebView 调试?

android - 如何获取对 WebView 系统 bundle 字体的字体引用? (格鲁吉亚,Times New Roman..)

Android Webview 不显示弹出窗口