我倾注了类似的问题,却找不到答案。我希望能够长时间在我的webview中按下用户上传的图像来保存它们(就像你可以在浏览器中一样)。有什么帮助吗?
更新
现在使用我自己的自定义项目“保存图像”弹出上下文菜单。我甚至可以成功干杯msgs。我如何保存图像呢?长时间点击的图像是否会传递到我的菜单项?
public boolean onLongClick(View v) {
openContextMenu(v);
return true;
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.context, menu);
}
@Override
public boolean onContextItemSelected(MenuItem item) {
AdapterContextMenuInfo info = (AdapterContextMenuInfo) item.getMenuInfo();
switch (item.getItemId()) {
case R.id.save_image:
Toast.makeText(this, "save failed",
Toast.LENGTH_LONG).show();
return true;
default:
return super.onContextItemSelected(item);
}
}
答案 0 :(得分:7)
首先在WebView中注册上下文菜单,如下所示:activity.registerForContextMenu(webView)
@Override
protected void onCreateContextMenu(ContextMenu menu) {
super.onCreateContextMenu(menu);
HitTestResult result = getHitTestResult();
MenuItem.OnMenuItemClickListener handler = new MenuItem.OnMenuItemClickListener() {
public boolean onMenuItemClick(MenuItem item) {
// do the menu action
return true;
}
};
if (result.getType() == HitTestResult.IMAGE_TYPE ||
result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
menu.setHeaderTitle(result.getExtra());
menu.add(0, ID_SAVEIMAGE, 0, "Save Image").setOnMenuItemClickListener(handler);
}
保存图片simply use this