feat(browser): 添加全屏功能- 在 WebViewActivity 中实现全屏切换功能 (#4404)
- 在菜单中添加全屏选项 - 更新多语言字符串文件,添加全屏相关翻译 Co-authored-by: SunQAQ <sunqi87c6@gmail.com>
This commit is contained in:
committed by
GitHub
co-authored by
SunQAQ
parent
6b6b53617a
commit
007ee2b17f
@@ -4,10 +4,13 @@ import android.annotation.SuppressLint
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.net.Uri
|
||||
import android.net.http.SslError
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.view.Menu
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import android.view.WindowInsets
|
||||
import android.view.WindowInsetsController
|
||||
import android.webkit.*
|
||||
import androidx.activity.addCallback
|
||||
import androidx.activity.viewModels
|
||||
@@ -89,10 +92,45 @@ class WebViewActivity : VMBaseActivity<ActivityWebViewBinding, WebViewModel>() {
|
||||
finish()
|
||||
}
|
||||
}
|
||||
R.id.menu_full_screen -> toggleFullScreen(item)
|
||||
}
|
||||
return super.onCompatOptionsItemSelected(item)
|
||||
}
|
||||
|
||||
private var isFullScreen = false
|
||||
|
||||
//实现starBrowser调起页面全屏
|
||||
private fun toggleFullScreen(item: MenuItem) {
|
||||
isFullScreen = !isFullScreen
|
||||
item.title = if (isFullScreen) "Exit full screen" else "Full screen"
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
// For API 30 and above
|
||||
val windowInsetsController = window.insetsController
|
||||
windowInsetsController?.let {
|
||||
if (isFullScreen) {
|
||||
it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||
it.hide(WindowInsets.Type.systemBars())
|
||||
supportActionBar?.hide()
|
||||
} else {
|
||||
it.show(WindowInsets.Type.systemBars())
|
||||
supportActionBar?.show()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// For older APIs
|
||||
@Suppress("DEPRECATION")
|
||||
window.decorView.systemUiVisibility = if (isFullScreen) {
|
||||
(View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
or View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION)
|
||||
} else {
|
||||
View.SYSTEM_UI_FLAG_VISIBLE
|
||||
}
|
||||
supportActionBar?.let { if (isFullScreen) it.hide() else it.show() }
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("JavascriptInterface", "SetJavaScriptEnabled")
|
||||
private fun initWebView(url: String, headerMap: HashMap<String, String>) {
|
||||
binding.progressBar.fontColor = accentColor
|
||||
|
||||
Reference in New Issue
Block a user