웹뷰에서 유뷰브 동영상에서 전체화면을 클릭하면 발생하는 에러를 처리하는 방법입니다.
웹크롬 클라이언트를 오브라이딩해서 처리해주면 됩니다.
문제점은 모든 기종은 테스트해보지 않았지만 아이스크림샌드위치 이상버전에서는 잘 동작하지만
갤럭시 2같이 진저브레드 버전에서는 동영상이 확대된 상태로 실행이 되니 버전을 체크해서 적절하게 구현해주면 됩니다. 출처 : http://nanstrong.tistory.com/216
import android.app.Activity; import android.content.Context; import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.webkit.JsResult; import android.webkit.WebChromeClient; import android.webkit.WebView; import android.widget.FrameLayout; public final class ChromeClient extends WebChromeClient { private View mCustomView; private Activity mActivity; public ChromeClient(Activity activity) { this.mActivity = activity; } @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { result.confirm(); return super.onJsAlert(view, url, message, result); } private int mOriginalOrientation; private FullscreenHolder mFullscreenContainer; private CustomViewCallback mCustomViewCollback; @Override public void onShowCustomView(View view, CustomViewCallback callback) { if (mCustomView != null) { callback.onCustomViewHidden(); return; } mOriginalOrientation = mActivity.getRequestedOrientation(); FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); mFullscreenContainer = new FullscreenHolder(mActivity); mFullscreenContainer.addView(view, ViewGroup.LayoutParams.MATCH_PARENT); decor.addView(mFullscreenContainer, ViewGroup.LayoutParams.MATCH_PARENT); mCustomView = view; mCustomViewCollback = callback; mActivity.setRequestedOrientation(mOriginalOrientation); } @Override public void onHideCustomView() { if (mCustomView == null) { return; } FrameLayout decor = (FrameLayout) mActivity.getWindow().getDecorView(); decor.removeView(mFullscreenContainer); mFullscreenContainer = null; mCustomView = null; mCustomViewCollback.onCustomViewHidden(); mActivity.setRequestedOrientation(mOriginalOrientation); } static class FullscreenHolder extends FrameLayout { public FullscreenHolder(Context ctx) { super(ctx); setBackgroundColor(ctx.getResources().getColor(android.R.color.black)); } @Override public boolean onTouchEvent(MotionEvent evt) { return true; } } }