首页 > 解决方案 > Android studio webview显示bug

问题描述

电池居中,但我没有使用任何边距或填充,我不知道该怎么做。我也用我的手机代替模拟器,但同样的问题。我试图在 chrome 中更改屏幕类型,它工作正常。

我的html代码:

    <style type="text/css">
html, body {height: 100%;}
h1,h2,h3,h4,h5,h6,p{color: white;}  

.pg2Header{ 
    background-color: #131313;
    border-radius: 0px 0px 150px 150px;
    width: 100%;
    height: 25%;
    padding-top: 10%;
    padding-left: 10%;
}
.statusTx{
    font-size: 30px;float: left;;width: -moz-fit-content;width: fit-content;display: table;
}    
.status{
    background-color: rgba(234,250,170,255);
    width: 45%;
    height: 20%;
    border-radius: 20px;
    padding-left: 1.5%;
    float: left;
}
</style>

<div class="pg2Header"><div><h1 style="float: left;  font-size: 60px;">barbelio b1</h1><img style="margin-left: 10px;height: 30%;width: 20%;" src="barbell.png"><img src="settings.png" style="margin-left: 30%;height: 40%;width: 7%;margin-bottom: 1%;"></div><img src="battery_big.png" style="margin-top: 7%"><div style="margin-top: 13%;width: 40%;float: right;"><h6 class="statusTx">Status:</h6><div class="status"><h6 style="color: black;" class="statusTx">Connected</h6></div></div></div>

我的科特林代码:

class MainActivity : AppCompatActivity() {
@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.activity_main)
    val myWebView: WebView = findViewById(R.id.webview)
    WebView.setWebContentsDebuggingEnabled(true);
    myWebView.settings.javaScriptEnabled = true
    myWebView.settings.domStorageEnabled = true;
    myWebView.webChromeClient = WebChromeClient()
    myWebView.addJavascriptInterface(WebAppInterface(this), "Android")
    myWebView.loadUrl("file:///android_asset/index.html")
}

}

导致浏览器

结果电话

标签: androidhtmlcssandroid-webview

解决方案


推荐阅读