如何在 android 中删除 Webview 的 header 边框

How to remove header border of webview in android

我想删除 Android app.To 中 WebView 的 header 边框 澄清一下,让我们看一张图片:

现在,在这张图片中,我用红色边框突出显示了站点的 header。我想删除 header 边框块。

这是我的 Android 代码:

MainActivity.java

package in.co.morenapantry.morenapantry;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {
    private WebView webView;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webView = (WebView) findViewById(R.id.webView2);
        webView.setWebViewClient(new WebViewClient());
        webView.loadUrl("url");

        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient());
    }
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

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

</android.support.constraint.ConstraintLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="in.co.morenapantry.morenapantry">
    <uses-permission android:name="android.permission.INTERNET"/>
    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label=""
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

您发布的 xml 中没有 toolbar/header xml 包含网络视图。 那么绿色 header/ 工具栏是如何加载的?

检查一次你的颜色文件和颜色原色,颜色原色深色。

我在浏览器中打开了您的 webview 加载 url 根据您的 xml 或代码,它应该像这样打开?

查看下面的 Web 视图实施教程。

https://www.google.com/amp/s/www.androidhive.info/2016/12/android-working-with-webview-building-a-simple-in-app-browser/amp/

只需在 AppTheme 中打开 styles.xml 添加这个

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

使用以下代码将您的清单添加到此 part.Change 您的 activity 主题样式。

    <activity android:name=".MainActivity"
        android:theme="@style/AppTheme.NoActionBar"> 
    </activity>