当我在网络视图中退出全屏视频时,该应用程序将变为空白,仅显示背景。我很茫然,似乎无法解决我的错误,这完全没问题,直到我迷路了并且忘记了定期检查代码。有人可以帮助解决我的问题并描述我做了什么。我从未使用过stackOverFlow,因此感谢任何人的帮助。
Java
superWebView = (VideoEnabledWebView) findViewById(R.id.mWebView);
ViewGroup videoLayout = (ViewGroup) findViewById(R.id.videoLayout); // Your own view, read class comments
webChromeClient = new VideoEnabledWebChromeClient(nonVideoLayout, videoLayout, superWebView) // See all available constructors...
{
};
webChromeClient.setOnToggledFullscreen(new VideoEnabledWebChromeClient.ToggledFullscreenCallback()
{
@Override
public void toggledFullscreen(boolean fullscreen)
{
// code to handle the full-screen change, showing and hiding
if (fullscreen)
{
searchBar.setVisibility(View.GONE);
backNav.setVisibility(View.GONE);
forwardNav.setVisibility(View.GONE);
refreshNav.setVisibility(View.GONE);
homeNav.setVisibility(View.GONE);
bottomNav.setVisibility(View.GONE);
searchNav.setVisibility(View.GONE);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
if (android.os.Build.VERSION.SDK_INT >= 14)
{
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
}
else
{
searchBar.setVisibility(View.VISIBLE);
superWebView.setVisibility(View.VISIBLE);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
if (android.os.Build.VERSION.SDK_INT >= 14)
{
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
}
});
superWebView.setWebChromeClient(webChromeClient);
}
XML
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mySwipeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
tools:context=".MainActivity"
tools:openDrawer="start">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/nonVideoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/browserlite_back"
android:orientation="vertical">
<FrameLayout
android:id="@+id/mFullscreenContainer"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<RelativeLayout
android:id="@+id/videoLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- View that will be shown while the fullscreen video loads (maybe include a spinner and a "Loading..." message) -->
<LinearLayout
android:id="@+id/searchBar_Background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:orientation="vertical">
<EditText
android:id="@+id/searchBar"
android:layout_width="match_parent"
android:layout_height="45dp"
android:layout_gravity="left|center"
android:layout_marginBottom="5dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="5dp"
android:elevation="5dp"
android:autoText="false"
android:autofillHints="@android:string/autofill"
android:background="@drawable/round_searchbar"
android:defaultFocusHighlightEnabled="true"
android:focusable="true"
android:gravity="left|center"
android:hint="Search or Enter URL"
android:inputType="none|text|textAutoCorrect|textAutoComplete|textUri"
android:linksClickable="true"
android:longClickable="true"
android:paddingEnd="5dp"
android:paddingLeft="10dp"
android:paddingRight="5dp"
android:paddingStart="10dp"
android:selectAllOnFocus="true"
android:singleLine="true"
android:soundEffectsEnabled="true"
android:textColor="#656565"
android:textSize="15dp"
android:textIsSelectable="true" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/searchBar_Background"
android:layout_gravity="center_horizontal|center_vertical"
android:gravity="center_vertical|center_horizontal"
android:orientation="horizontal">
<Button
android:id="@+id/buttonWeather"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:elevation="5dp"
android:background="@drawable/rounded_button"
android:text="Weather" />
<Button
android:id="@+id/buttonNews"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:elevation="5dp"
android:background="@drawable/rounded_button"
android:text="News" />
<Button
android:id="@+id/buttonDDG"
android:layout_width="80dp"
android:layout_height="80dp"
android:layout_marginBottom="10dp"
android:layout_marginEnd="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:elevation="5dp"
android:background="@drawable/rounded_button"
android:text="DDG" />
</LinearLayout>
<com.okaybrowser.okaybrowserfastprivate.VideoEnabledWebView
android:id="@+id/mWebView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@id/bottomNav"
android:layout_below="@+id/searchBar_Background"
android:layout_gravity="center"
android:background="#ffffff"
android:contextClickable="true">
</com.okaybrowser.okaybrowserfastprivate.VideoEnabledWebView>
<LinearLayout
android:id="@+id/myLinearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ProgressBar
android:id="@+id/myProgressBar"
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:background="#ff00fe"
android:layout_height="2dp"
android:layout_weight="1" />
</LinearLayout>
<View
android:id="@+id/videoLoading"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:visibility="invisible" />
<LinearLayout
android:id="@+id/bottomNav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#ffffff"
android:gravity="center_horizontal|center_vertical"
android:orientation="horizontal">
<Button
android:id="@+id/backNav"
android:layout_width="35dp"
android:layout_height="38dp"
android:layout_marginEnd="20dp"
android:layout_marginRight="20dp"
android:background="@drawable/ic_keyboard_arrow_left_black_24dp" />
<Button
android:id="@+id/forwardNav"
android:layout_width="35dp"
android:layout_height="38dp"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/ic_keyboard_arrow_right_black_24dp" />
<Button
android:id="@+id/homeNav"
android:layout_width="35dp"
android:layout_height="38dp"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/ic_home_grey_24dp" />
<Button
android:id="@+id/refreshNav"
android:layout_width="35dp"
android:layout_height="38dp"
android:layout_marginEnd="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/ic_refresh_grey_24dp" />
<Button
android:id="@+id/searchNav"
android:layout_width="35dp"
android:layout_height="38dp"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:background="@drawable/ic_search_grey_24dp" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="56dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#273238"
app:itemIconTint="#ffffff"
app:menu="@menu/drawer_menu">
</android.support.design.widget.NavigationView>
答案 0 :(得分:0)
尝试这个
webChromeClient.setOnToggledFullscreen(new VideoEnabledWebChromeClient.ToggledFullscreenCallback()
{
@Override
public void toggledFullscreen(boolean fullscreen)
{
// code to handle the full-screen change, showing and hiding
if (fullscreen)
{
searchBar.setVisibility(View.GONE);
backNav.setVisibility(View.GONE);
forwardNav.setVisibility(View.GONE);
refreshNav.setVisibility(View.GONE);
homeNav.setVisibility(View.GONE);
bottomNav.setVisibility(View.GONE);
searchNav.setVisibility(View.GONE);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags |= WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
if (android.os.Build.VERSION.SDK_INT >= 14)
{
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}
}
else
{
searchBar.setVisibility(View.VISIBLE);
backNav.setVisibility(View.VISIBLE);
forwardNav.setVisibility(View.VISIBLE);
refreshNav.setVisibility(View.VISIBLE);
homeNav.setVisibility(View.VISIBLE);
bottomNav.setVisibility(View.VISIBLE);
searchNav.setVisibility(View.VISIBLE);
WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
attrs.flags &= ~WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON;
getWindow().setAttributes(attrs);
if (android.os.Build.VERSION.SDK_INT >= 14)
{
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
}
});
答案 1 :(得分:0)
建议:
为什么不使用其他活动以全屏方式仅在WebView中播放视频。然后,在完成视频后,完成活动。通过这样做,您可以使一切顺利。您也不必担心可视性。