2013-10-29 32 views
0

有一个网站,我用它在桌面上的新窗口中打开,现在我想要做的就是在应用程序中复制它。我到目前为止的代码包含了setsupportformultiplewindows,但是当我点击打开新窗口的链接时,什么也没有发生。我的浏览器代码如下为什么没有在弹出的webview中打开链接?

public class WebActivity extends Activity { 

private WebView mWebView = null; 
private EditText mInputUrl = null; 


/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
this.getWindow().requestFeature(Window.FEATURE_PROGRESS); 
super.onCreate(savedInstanceState); 
getWindow().setFeatureInt(Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON); 
setContentView(R.layout.activity_web_view); 

Intent intent = getIntent(); 
String thesite = intent.getStringExtra(MainPage.EXTRA_MESSAGE); 

mInputUrl = (EditText)findViewById(R.id.input_url); 
Button button = (Button)findViewById(R.id.button); 
button.setOnClickListener(new View.OnClickListener() { 

     @Override 
     public void onClick(View v) { 
      String baseurl = "http://"; 
      String url = baseurl + mInputUrl.getText().toString(); 
      mWebView.loadUrl(url); 
     } 
    }); 

mWebView = (WebView) findViewById(R.id.webview); 
mWebView.loadUrl(thesite); 
mWebView.getSettings().setJavaScriptEnabled(true); 
mWebView.setWebViewClient(new WebViewClient()); 
mWebView.getSettings().setAllowFileAccess(true); 
mWebView.getSettings().setPluginState(WebSettings.PluginState.ON); 
mWebView.getSettings().setBuiltInZoomControls(true); 
mWebView.getSettings().setLoadWithOverviewMode(true); 
mWebView.getSettings().setUseWideViewPort(true); 
mWebView.getSettings().setGeolocationEnabled(true); 
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 
mWebView.getSettings().setSupportMultipleWindows(true); 

final Activity MyActivity = this; 
mWebView.setWebChromeClient(new WebChromeClient() { 
    public void onGeolocationPermissionsShowPrompt(String origin, android.webkit.GeolocationPermissions.Callback callback) { 
     callback.invoke(origin, true, false); 
    } 

有进一步下面的代码而不是与我的问题

编辑:

这里是一个展示如何我会非常喜欢它的图像。 https://www.dropbox.com/s/gwllmjebtw13rzw/webview.png

+0

哪一个Url加载? mwebView.loadurl(theSite)或mWebView.loadUrl(url)?? –

+0

默认视图是用于地址栏的mwebView.loadurl(theSite),mWebView.loadUrl(url)我有 – j1mmyg88

+0

这个加载是否正确? –

回答

0

试试这个:

mWebView.setWebChromeClient(new WebChromeClient() { 


    @Override 
    public void onPageStarted(WebView view, String url, Bitmap favicon) { 
     super.onPageStarted(view, url, favicon); 

    } 

    @Override 
    public void onLoadResource(WebView view, String url) { 
     super.onLoadResource(view, url); 

    } 

    @Override 
    public boolean shouldOverrideUrlLoading(WebView view, String url) { 


      Intent webIntent = new Intent(WebViewActivity.this, 
        NewWebViewActivity.class); 
      webIntent .putExtra("urlparam", url); 
      startActivity(webIntent); 

     return true; 

    } 

    @Override 
    public void onPageFinished(WebView view, String url) { 
     super.onPageFinished(view, url); 

    } 
} 

在shouldOverrideUrlLoading(),您可以检查URL和使用startActivity在另一个活动中打开它()。

希望这会有所帮助。

+0

会给这样的事情吗? [https://www.dropbox.com/s/gwllmjebtw13rzw/webview.png](https://www.dropbox.com/s/gwllmjebtw13rzw/webview.png) – j1mmyg88

+0

这将在新活动中打开网址网页流量。 –

+0

你知道像我附加的图片一样吗? – j1mmyg88