Last active
December 28, 2015 16:50
-
-
Save vincent1086/0caa27c98d96b7c22bad to your computer and use it in GitHub Desktop.
Android WebView HTML Video full screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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