Skip to content

Instantly share code, notes, and snippets.

@vincent1086
Last active December 28, 2015 16:50
Show Gist options
  • Save vincent1086/0caa27c98d96b7c22bad to your computer and use it in GitHub Desktop.
Save vincent1086/0caa27c98d96b7c22bad to your computer and use it in GitHub Desktop.
Android WebView HTML Video full screen
<FrameLayout
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="300dip" >
<WebView
android:id="@+id/webview"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
<FrameLayout
android:id="@+id/targetview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
WebView mWebView = (WebView) findViewById(R.id.webview);
mClient = new MyChromeClient();
mWebView.setWebChromeClient(mClient);
mWebView.loadUrl("file:///android_asset/test.html");
mContentView = (FrameLayout) findViewById(R.id.main_content);
mTargetView = (FrameLayout)findViewById(R.id.targetview);
}
@Override
public void onBackPressed(){
if (mCustomView != null){
mClient.onHideCustomView();
}else{
finish();
}
}
class MyChromeClient extends WebChromeClient {
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
mCustomViewCallback = callback;
mTargetView.addView(view);
mCustomView = view;
mContentView.setVisibility(View.GONE);
mTargetView.setVisibility(View.VISIBLE);
mTargetView.bringToFront();
}
@Override
public void onHideCustomView() {
if (mCustomView == null)
return;
mCustomView.setVisibility(View.GONE);
mTargetView.removeView(mCustomView);
mCustomView = null;
mTargetView.setVisibility(View.GONE);
mCustomViewCallback.onCustomViewHidden();
mContentView.setVisibility(View.VISIBLE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment