前言
之前也做过了,很多遍全屏的控制,但是一直都没有写成笔记去总结。
webview setting
this.getSettings().setJavaScriptEnabled(true);
this.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);
this.getSettings().setDomStorageEnabled(true);//开启 DOM storage API 功能
this.getSettings().setDatabaseEnabled(true);//开启 database storage API 功能
this.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);//设置缓存
String cacheDirPath = getContext().getFilesDir().getAbsolutePath() + APP_CACAHE_DIRNAME;
this.getSettings().setAppCacheEnabled(true);
//设置 Application Caches 缓存目录
this.getSettings().setAppCachePath(cacheDirPath);
this.getSettings().setUseWideViewPort(true);
this.getSettings().setDisplayZoomControls(true);
//设置全屏播放
this.getSettings().setLoadWithOverviewMode(true);
this.getSettings().setAllowFileAccess(true);
this.getSettings().setSupportZoom(true);
this.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
this.getSettings().setPluginState(WebSettings.PluginState.ON);
WebChromeClient重写onShowCustomView和onHideCustomView方法
View myVideoView;
View myNormalView;
CustomViewCallback callback;
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
fullScreen();
//将videoview 添加到framelayout
ViewGroup viewGroup = (ViewGroup) flVideoContent.getParent();
viewGroup.removeView(flVideoContent);
viewGroup.addView(view);
myVideoView = view;
myNormalView = flVideoContent;
this.callback = callback;
super.onShowCustomView(view, callback);
}
@Override
public void onHideCustomView() {
fullScreen();
//将videoview 移出 framelayout
if (callback != null) {
callback.onCustomViewHidden();
callback = null;
}
if (myVideoView != null) {
ViewGroup viewGroup = (ViewGroup) myVideoView.getParent();
viewGroup.removeView(myVideoView);
viewGroup.addView(myNormalView);
}
super.onHideCustomView();
}
重写onConfigurationChanged方法
重写此方法用于解决屏幕反转问题
@Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
switch (config.orientation) {
case Configuration.ORIENTATION_LANDSCAPE://横屏
//清空非全屏
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
//设置全屏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
break;
case Configuration.ORIENTATION_PORTRAIT://竖屏
//清空全屏
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
//设置不全屏
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
break;
}
}
/**
* 切换屏幕,使得屏幕旋转
*/
private void fullScreen() {
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
jyTitleBar.setVisibility(View.GONE);
Log.i("xxx","横屏");
} else {
//解决标题影响绘制问题
jyTitleBar.setVisibility(View.VISIBLE);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
Log.i("xxx","竖屏");
}
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TitleBar
android:id="@+id/jyTitleBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:jy_right_text="保存"
app:jy_show_right_image="false"
app:jy_left_image="@drawable/ic_btn_return" />
<JYWebView
android:id="@+id/webView"
android:layout_below="@id/jyTitleBar"
style="@style/scrollview_style"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/fl_video_content"
android:background="@color/c_F5F6FA"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
结束语
每天记一记,总会再用到的
2414



被折叠的 条评论
为什么被折叠?



