zoukankan      html  css  js  c++  java
  • android开发webview使用h5播放视频时横竖屏切换的解决方法

    1.xml代码
    <activity
    android:hardwareAccelerated="true"
    android:name=".WebViewActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:screenOrientation="portrait" />

    2.kotlin代码
    webView.webChromeClient = object : WebChromeClient() {
    override fun onShowCustomView(view: View, callback: WebChromeClient.CustomViewCallback) {
    super.onShowCustomView(view, callback)
    showCustomView(view, callback)
    }
    override fun onHideCustomView() {
    super.onHideCustomView()
    hideCustomView()
    }
    }

    private fun setStatusBarVisibility(visible: Boolean) {
    val flag = if (visible) 0 else WindowManager.LayoutParams.FLAG_FULLSCREEN
    window.setFlags(flag, WindowManager.LayoutParams.FLAG_FULLSCREEN)
    }

    private var customView: View? = null
    private var customViewCallback: WebChromeClient.CustomViewCallback? = null

    private fun showCustomView(view: View, callback: IX5WebChromeClient.CustomViewCallback) {
    requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
    if (customView != null || view.parent != null) {
    callback.onCustomViewHidden()
    return
    }
    (window.decorView as FrameLayout).addView(view, FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT))
    customView = view
    setStatusBarVisibility(false)
    customViewCallback = callback
    }

    private fun hideCustomView() {
    requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
    if (customView == null) {
    return
    }
    setStatusBarVisibility(true)
    (window.decorView as FrameLayout).removeView(customView)
    customView = null
    customViewCallback?.onCustomViewHidden()
    webView.visibility = View.VISIBLE
    }
  • 相关阅读:
    Python爬虫爬取糗事百科段子内容
    Python 的安装与配置(Windows)
    接口测试(二)—HttpClient
    接口测试(一)
    第一篇 什么是软件测试
    Python数据分析与挖掘第一篇—基本介绍及环境搭建
    从零开始搭建简易的异步非阻塞web框架
    Python多线程补充—GIL
    Python并发之多进程
    Python并发之多线程
  • 原文地址:https://www.cnblogs.com/yongfengnice/p/13713674.html
Copyright © 2011-2022 走看看