gpt4 book ai didi

javascript - 如何使html在android浏览器的webview上填充全屏高度

转载 作者:行者123 更新时间:2023-11-28 05:48:48 27 4
gpt4 key购买 nike

我在 AppCompatActivity 上添加了一个 webview,并想让它全屏显示。我已经尝试过此链接 ( How to make full screen in Android 4.0 ) 中提到的方法,但它没有帮助。

下面是布局xml文件。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.lenovo.mds.mbgcompass.MainActivity">

<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webView"
/>
</RelativeLayout>

下面是 MainActivity 类:

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);

webView = (WebView) findViewById(R.id.webView);
setupWebView();
}

private void setupWebView(){
webView.getSettings().setSupportZoom(true);
webView.getSettings().setBuiltInZoomControls(false);
webView.getSettings().setCacheMode(android.webkit.WebSettings.LOAD_NO_CACHE);
webView.getSettings().setDefaultTextEncodingName("UTF-8");
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setDatabaseEnabled(true);
webView.getSettings().setDomStorageEnabled(true);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setJavaScriptCanOpenWindowsAutomatically(true);
webView.getSettings().setLoadWithOverviewMode(true);
webView.loadUrl("file:///android_asset/index.html");
}

下面是使 html dom 为 100% 高度的 html css 样式。但它不适用于安卓浏览器。如果我将高度更改为“100hv”,它只适用于 chrome 浏览器而不适用于 android 浏览器。我还应该尝试什么来使 html dom 填充屏幕的 100% 高度?

var style = {
width: '100%',
margin: '0 auto',
height: '100%'
}

请看下面的截图。我认为 webview 正在填充设备的全屏,但 webview 中的 html 没有填充。如何在底部填充空间?

enter image description here

最佳答案

里面没有问题。但是,按如下方式编辑您的 xml 文件:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.lenovo.mds.mbgcompass.MainActivity">

<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:id="@+id/webView"
/>
</RelativeLayout>

关于javascript - 如何使html在android浏览器的webview上填充全屏高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37456379/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com