java - 删除 Android webview 左右边距

标签 java android android-studio webview sdk

我正在开发一个 webview 应用程序,我的问题是左右两侧都有空白,我是初学者,我不知道如何删除它们,请帮忙。 注意:请在您的答案中具体说明,例如:在名为布局的 java 框中的全屏内容中添加此代码。

非常感谢,这是代码: 1-布局-全屏 Activity 文件夹

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_fullscreen);
        WebView view = (WebView) this.findViewById(R.id.webView);
        view.setWebViewClient(new WebViewClient());
        view.loadUrl("http://google.com");

        view.getSettings().setJavaScriptEnabled(true);

        mVisible = true;
        mControlsView = findViewById(R.id.webView);
        mContentView = findViewById(R.id.webView);


        // Set up the user interaction to manually show or hide the system UI.
        mContentView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                toggle();
            }
        });

        // Upon interacting with UI controls, delay any scheduled hide()
        // operations to prevent the jarring behavior of controls going away
        // while interacting with the UI.

    }



    @Override
    protected void onPostCreate(Bundle savedInstanceState) {
        super.onPostCreate(savedInstanceState);

// Trigger the initial hide() shortly after the activity has been
        // created, to briefly hint to the user that UI controls
        // are available.
        delayedHide(100);


    }

    private void toggle() {
        if (mVisible) {
            hide();
        } else {
            show();
        }
    }

    private void hide() {
        // Hide UI first
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
            actionBar.hide();
        }
        mControlsView.setVisibility(View.GONE);
        mVisible = false;

ma​​nifest文件夹中的2-android manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="eizeasta.resale">
    <uses-permission android:name="android.permission.INTERNET" />



    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity
            android:name=".FullscreenActivity"
            android:configChanges="orientation|keyboardHidden|screenSize"
            android:label="@string/app_name"
            android:theme="@style/FullscreenTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

java文件夹中的3-activity全屏

<FrameLayout 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"
    android:background="#0099cc"
    tools:context="eizeasta.resale.FullscreenActivity">

    <!-- The primary full-screen view. This can be replaced with whatever view
         is needed to present your content, e.g. VideoView, SurfaceView,
         TextureView, etc. -->

    <TextView
        android:id="@+id/fullscreen_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:keepScreenOn="true"
        android:text="@string/dummy_content"
        android:textColor="#33b5e5"
        android:textSize="50sp"
        android:textStyle="bold" />

    <!-- This FrameLayout insets its children based on system windows using
         android:fitsSystemWindows. -->

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

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true">

        <LinearLayout
            android:id="@+id/fullscreen_content_controls"
            style="?metaButtonBarStyle"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="bottom|center_horizontal"
            android:background="@color/black_overlay"
            android:orientation="horizontal"
            tools:ignore="UselessParent">

        </LinearLayout>

    </FrameLayout>

</FrameLayout>

最佳答案

我发现了问题,只是添加了这段代码,webview 适合全屏。

mWebView.getSettings().setUseWideViewPort(true);
        mWebView.getSettings().setLoadWithOverviewMode(true);

关于java - 删除 Android webview 左右边距,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40310175/

相关文章:

android - 如何在 Android 的进度条中显示下载进度?

android - MonoTouch/MonoDroid 服务层不兼容?

java - 在我的应用程序中使用 selenium,无需任何外部服务器

java - Android Studio 中的 ImageButton 问题

android - 无法将bluestacks与android studio连接到本地主机:5555 in windows

java - 具有匿名内部类的 Spring AOP

java - 如何通过名称而不是值获取 TreeView 分支?

java - 练习 2.2 的数学公式 - 梁丹尼尔

java - Eclipse Java 代码格式化

android - 仅在生成签名 APK 时 Android Studio 3 中出现 "Cannot load keystore"错误