我使用的网站在桌面上的新窗口中打开,现在我要做的就是在应用程序中复制它。到目前为止我的代码包括setsupportformultiplewindows但是当我点击打开新窗口的链接时,没有任何反应。我的浏览器代码如下
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 :(得分: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()中,您可以使用startActivity()检查网址并在另一个活动中打开它。
希望这有帮助。