在USB上调试时,我只是想将WebView扩展为全屏。不幸的是,白色屏幕出现后没有任何内容。我真的不知道该怎么办。我制作了CustomView,一切都很好。这是我的代码:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
filmkey = "<iframe width=\"96%\" height=\"96%\" src=\"https://www.youtube.com/embed/EtMOgsWEAmQ\" frameborder=\"0\" allowfullscreen></iframe>";
screen=(WebView)findViewById(R.id.webView);
screen.getSettings().setJavaScriptEnabled(true);
String myvideokey = filmkey;
screen.loadData(myvideokey, "text/html", "utf-8");
screen.setWebChromeClient(new WebChromeClient(){
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
}
@Override
public void onHideCustomView() {
super.onHideCustomView();
}
});
}
答案 0 :(得分:0)
尝试以下代码。在这个全屏幕上,我创建了一个View
,它将成为全屏。
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (savedInstanceState != null) {
screen.restoreState(savedInstanceState);
}
setContentView(R.layout.activity_support);
filmkey = "<iframe width=\"96%\" height=\"96%\" src=\"https://www.youtube.com/embed/EtMOgsWEAmQ\" frameborder=\"0\" allowfullscreen></iframe>";
screen=(WebView)findViewById(R.id.webview);
screen.getSettings().setJavaScriptEnabled(true);
String myvideokey = filmkey;
screen.loadData(myvideokey, "text/html", "utf-8");
CustomWebChromeClient custom = new CustomWebChromeClient();
screen.setWebChromeClient(custom);
}
,自定义WebChromeClient
是
class `CustomWebChromeClient` extends WebChromeClient{
@Override
public void onShowCustomView(View view, final CustomViewCallback callback) {
super.onShowCustomView(view, callback);
Dialog dialog = new Dialog(SupportActivity.this, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
view.setBackgroundColor(Color.TRANSPARENT);
dialog.setContentView(view);
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
callback.onCustomViewHidden();
}
});
dialog.show();
}
@Override
public void onHideCustomView() {
super.onHideCustomView();
}
}
并确保您在活动中使用所有这些方法来处理webView
中的数据。
@Override
protected void onResume() {
super.onResume();
screen.onResume();
}
@Override
protected void onPause() {
super.onPause();
screen.onPause();
}
@Override
protected void onStop() {
super.onStop();
screen.stopLoading();
}
@Override
protected void onDestroy() {
super.onDestroy();
screen.destroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
screen.saveState(outState);
}
我希望它有所帮助。