有些人可能会标记为重复问题。在将其标记为副本之前,请仔细阅读我的问题。这两天我遇到了这个问题。我已经尝试了从stackoverflow中得到的所有答案,甚至从github克隆了一些项目。但是没有一个答案对我有效,最重要的部分是几天前同样的代码对我有效。我得到的所有答案都是很久以前的事了。如果可以的话,请帮帮我。在我的代码下面
webView.setWebViewClient(new AppWebViewClients());
webView.setWebChromeClient(new MyWebClient());
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
webView.getSettings().setMediaPlaybackRequiresUserGesture(false);
}
try {
webView.loadUrl("https://www.youtube.com/watch?v=hlvbDjksdCg");
} catch (Exception e) {
Log.d(TAG, "run: " + e.getMessage());
}MyWebClient
public class MyWebClient
extends WebChromeClient {
private View mCustomView;
private WebChromeClient.CustomViewCallback mCustomViewCallback;
protected FrameLayout mFullscreenContainer;
private int mOriginalOrientation;
private int mOriginalSystemUiVisibility;
MyWebClient() {
}
public Bitmap getDefaultVideoPoster() {
if (StreamActivity.this == null) {
return null;
}
return BitmapFactory.decodeResource(StreamActivity.this.getApplicationContext().getResources(), 2130837573);
}
public void onHideCustomView() {
((FrameLayout) StreamActivity.this.getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
StreamActivity.this.getWindow().getDecorView().setSystemUiVisibility(0);
StreamActivity.this.setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback) {
if (this.mCustomView != null) {
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = StreamActivity.this.getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = StreamActivity.this.getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout) StreamActivity.this.getWindow().getDecorView()).addView(this.mCustomView, new FrameLayout.LayoutParams(-1, -1));
StreamActivity.this.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
}
}最后是webview客户端
公共类AppWebViewClients扩展了WebViewClient {
AppWebViewClients() {
pd=Util.createProgressDialog(StreamActivity.this);
pd.show();
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
pd.dismiss();
}
}发布于 2019-04-16 17:49:06
尝尝这个
@Override
public void onHideCustomView() {
((FrameLayout) StreamActivity.this.getWindow().getDecorView()).removeView(this.mCustomView);
this.mCustomView = null;
StreamActivity.this.getWindow().getDecorView().setSystemUiVisibility(mOriginalSystemUiVisibility);
StreamActivity.this.setRequestedOrientation(this.mOriginalOrientation);
this.mCustomViewCallback.onCustomViewHidden();
this.mCustomViewCallback = null;
}
@Override
public void onShowCustomView(View paramView, WebChromeClient.CustomViewCallback paramCustomViewCallback) {
if (this.mCustomView != null) {
onHideCustomView();
return;
}
this.mCustomView = paramView;
this.mOriginalSystemUiVisibility = StreamActivity.this.getWindow().getDecorView().getSystemUiVisibility();
this.mOriginalOrientation = StreamActivity.this.getRequestedOrientation();
this.mCustomViewCallback = paramCustomViewCallback;
((FrameLayout) StreamActivity.this.getWindow().getDecorView()).addView(this.mCustomView,
new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT));
int visibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
visibility = visibility | View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
visibility = visibility | View.SYSTEM_UI_FLAG_IMMERSIVE;
}
StreamActivity.this.getWindow().getDecorView().setSystemUiVisibility(visibility);
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
}并且必须在AndroidManifest.xml中设置activity configChanges属性
<activity
android:name=".StreamActivity"
...
android:configChanges="keyboardHidden|orientation|screenSize" />https://stackoverflow.com/questions/55703912
复制相似问题