我正在使用Android Webview制作应用。
并使用“ setWebChromeclient”控制“ window.open”
我有两个问题。
向上滚动“ webView”->“ window.open”-> setWebChromeClient-> onCreateWindow->新childWebview
但是“ chidView”位置在文档的顶部。
如何到达“手机”屏幕的顶部?
我想在底部添加一个关闭按钮。
子网页视图是否可以设置layout.xml?
感谢您阅读本文。
public class MainActivity extends Activity {
WebView webView;
WebView childView;
@Override
protected void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_PROGRESS);
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webview);
webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setSupportMultipleWindows(true);
webSettings.setGeolocationEnabled(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
webSettings.setBuiltInZoomControls(true);
webView.setWebChromeClient(new MyWebChromeClient());
webView.setWebViewClient(new WebViewClient() {
......
});
webView.loadUrl(startUrl);
}
private class MyWebChromeClient extends WebChromeClient {
@Override
public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) {
webView.removeAllViews();
childView = new WebView(MainActivity.this);
childView.getSettings().setJavaScriptEnabled(true);
childView.setWebChromeClient(this);
webView.addView(childView);
WebView.WebViewTransport transport = (WebView.WebViewTransport) resultMsg.obj;
transport.setWebView(childView);
resultMsg.sendToTarget();
return true;
}
}
}