我的应用程序中的一个片段是在webview中显示我网站上的文章。允许更改我放置的方向
android:configChanges="orientation|screenSize"
在我的活动清单中。
除了在片段中显示的webview之外,其他一切都正常工作。当我将屏幕方向从横向更改为纵向时,webview如下所示
this
check it here
.
here
和
here
.
我的片段中webview的配置:
contentWebView = view.findViewById(R.id.contentWebView);
contentWebView.setWebChromeClient(new FullScreenInWebviewClient(contentRelativeLayout,
contentWebView, mainActivity.getSupportActionBar()));
contentWebView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url){
Uri uri = Uri.parse(url);
if(url != null && (url.startsWith("http://") || url.startsWith("https://"))){
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, uri));
return true;
} else{
return false;
}
}
});
contentWebView.setLayoutParams(new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
WebSettings webSettings = contentWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
webSettings.setLoadsImagesAutomatically(true);
webSettings.setLoadWithOverviewMode(true);
webSettings.setUseWideViewPort(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAllowContentAccess(true);
webSettings.setJavaScriptCanOpenWindowsAutomatically(true);
我的相对布局文件:
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/contentWebView"
android:clickable="true"
android:focusable="true"/>
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/contentProgressBar"
android:background="@xml/progress"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
/>
编辑:
我从webview中删除了这些广告,并用Google adMob在我的应用程序中实现了这些广告。现在改变方向完全没有任何问题。