一、支持网页视频播放
设置自定义WebChromeClient,覆写 onShowCustomView
、onHideCustomView
,将WebChromeClient提供的 view 添加到布局中即可。
webChromeClient = object : WebChromeClient() { override fun onShowCustomView(view: View?, callback: CustomViewCallback?) { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE mViewBinding.flVideoContainer.run { visibility = View.VISIBLE addView(view) } } override fun onHideCustomView() { requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR mViewBinding.flVideoContainer.run { visibility = View.GONE removeAllViews() } } }继续阅读“Android WebView相关交互实现”