android 嵌套webview 全屏展示 页面延伸到状态栏且不被底部导航栏遮挡

我的项目是使用webview嵌套了一个uniapp打包出的h5
本来展示很正常,某天突然发现uniapp的底部导航被手机底部的导航栏挡住了,离奇,某天突然出现的
有些手机会设置展示底部导航按钮,有些手机会关闭底部导航
以下代码对这两种情况通用

package org.topsec.viewer

import android.os.Bundle
import android.util.Log
import android.webkit.WebView
import android.widget.FrameLayout
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import kotlin.concurrent.thread
import android.view.View
// Singleton
class MainActivity : AppCompatActivity() {
    val spiceJNI = SpiceJNI(this)
    val spiceJSInterface = SpiceJSInterface(this)
    val spiceWebViewClient = SpiceWebViewClient(this)
    private lateinit var layoutView : View
    lateinit var webView: WebView

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        WindowCompat.setDecorFitsSystemWindows(window, false)

        setContentView(R.layout.webview_layout)
        supportActionBar?.hide()

        webView = findViewById(R.id.web_view)
        val rootView = findViewById<FrameLayout>(R.id.root_frame)

        ViewCompat.setOnApplyWindowInsetsListener(rootView) { view, insets ->
            val systemBarsInsets = insets.getInsets(WindowInsetsCompat.Type.systemBars())

            Log.d("InsetsDebug", "Top system bar height: ${systemBarsInsets.top}px")
            Log.d("InsetsDebug", "Bottom system bar height: ${systemBarsInsets.bottom}px")

            // 为根布局设置所有方向的内边距
            view.updatePadding(
                left = systemBarsInsets.left,
                0,
                right = systemBarsInsets.right,
                bottom = systemBarsInsets.bottom
            )

            insets
        }

        // 其他WebView设置
        webView.settings.javaScriptEnabled = true
        webView.webViewClient = spiceWebViewClient
        webView.settings.supportZoom()
        webView.settings.loadWithOverviewMode = true
        webView.settings.builtInZoomControls = true
        webView.settings.displayZoomControls = true
        webView.addJavascriptInterface(spiceJSInterface, "spiceInterface")
        webView.settings.domStorageEnabled = true
        webView.settings.databaseEnabled = true

        webView.loadUrl("file:///android_asset/web/index.html")
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值