当用户单击WebView中的链接时,显示“使用完整操作”对话框

时间:2016-10-13 17:19:37

标签: android webview

当用户点击webview中的链接时,我想显示“使用完整操作”对话框。这是一个例子: Click here to see the image.

我的代码:

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    final WebView myWebView = (WebView)findViewById(R.id.webView);
    myWebView.setWebViewClient(new WebViewClient());
    myWebView.setWebChromeClient(new WebChromeClient());
    myWebView.getSettings().setJavaScriptEnabled(true);
    WebSettings webSettings = myWebView.getSettings();
    webSettings.setTextSize(WebSettings.TextSize.NORMAL);
    myWebView.getSettings().setDomStorageEnabled(true);
    myWebView.getSettings().setDatabaseEnabled(true);
    myWebView.getSettings().setAllowUniversalAccessFromFileURLs(true);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        myWebView.getSettings().setDatabasePath("/data/data/" + myWebView.getContext().getPackageName() + "/databases/");
    }
    final Button mButton = (Button)findViewById(R.id.button);
    final EditText  mEdit = (EditText)findViewById(R.id.editText);

    mButton.setOnClickListener(
            new View.OnClickListener() {
                public void onClick(View view) {
                    String strUrl=mEdit.getText().toString();
                    if(strUrl.length()>0)
                        myWebView.loadUrl(strUrl);

                }
            });

    Button newButton = (Button)findViewById(R.id.new_button);
    newButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            myWebView.loadUrl( "javascript:window.location.reload( true )" );
        }
    });





}

 }

我应该在代码中包含哪些内容来实现这一目标?

1 个答案:

答案 0 :(得分:0)

我认为您应该在设置网络客户端方面做点什么

webview.setWebViewClient(new WebViewClient()
{
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        you will have url hear you can set your "complete action" hear 

        return true;
    }
});