在project下的build.gradle添加
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
在module下的build.gradle添加
dependencies {
compile 'com.github.CarGuo:CustomActionWebView:v1.0.1'
}
在清单文件加上联网的权限
在布局中:
<com.shuyu.action.web.CustomActionWebView
android:id="@+id/wv"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
在activity中:
wv = (CustomActionWebView) findViewById(R.id.wv);
List<String> list = new ArrayList<>();
list.add("随便1");
list.add("随便12");
list.add("随便13");
WebSettings settings = wv.getSettings();
settings.setJavaScriptEnabled(true);
wv.setActionList(list);
//链接js注入接口,使能选中返回数据
wv.linkJSInterface();
wv.loadUrl("http://www.jianshu.com/p/b32187d6e0ad");
wv.setActionSelectListener(new ActionSelectListener() {
@Override
public void onClick(String s, String s1) {
Toast.makeText(MainActivity.this, "Click Item: " + s + "。\n\nValue: " + s1, Toast.LENGTH_LONG).show();
}
});
类似于长按文章,有复制,收藏的功能
最新推荐文章于 2022-04-15 16:33:25 发布