How to have a WebView in full screen?

2

My specific question: How do I open a% s of full screen% in Android Studio?

Change Theme in Manifest? Change Theme in XML? Force a JAVA script? Change the view's borders? Change code in Style?

All these attempts quoted above have been thoroughly tested, mainly from foreign websites. Even when I search for content in English, I see the difficulty of finding the solution for a full-screen webview. Often the supposed solution is to hide the application's title bar, leaving that margin in the application, not solving the specific problem. My project looks like this:

Manifest

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.duff.webviewoficial">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/TelaCheia">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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


    </application>
    <uses-permission android:name="android.permission.INTERNET" />

</manifest>

MainActivity.java

package com.example.duff.webviewoficial;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class MainActivity extends AppCompatActivity {



    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        getSupportActionBar().hide(); //aqui a mágica   REMOVE A BARRA DE TITULO
        getWindow().setFeatureInt( Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);
        setContentView(R.layout.activity_main);


        WebView mWebView = (WebView) findViewById(R.id.activity_main_webview);

        // Enable Javascript
        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true); // Aparentemente habilitado

        mWebView.setWebViewClient(new WebViewClient()
        {
         public boolean shouldOverrideUrlLoading(WebView view, String url){
             view.loadUrl(url);
             return false;
         }
        });


        mWebView.loadUrl("http://duffproapps.16mb.com/appFinal/home2.html");
        //mWebView.loadUrl("file:///android_asset/index.html");
        //http://duffproapps.16mb.com/appFinal/


    }


}

activity_main.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:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    tools:context="com.example.duff.webviewoficial.MainActivity">


    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"></LinearLayout>

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




        />

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">

    </RelativeLayout>

</RelativeLayout>

style.xml

<resources>

    <!-- Base application theme. -->
    <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="android:windowTranslucentStatus">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>

    <style name="TelaCheia" parent="Theme.AppCompat.Light.DarkActionBar" >
        <item name="android:colorBackground">@color/background_material_light</item>
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowTranslucentStatus">true</item>
        <item name="android:windowFullscreen">true</item>
    </style>

</resources>
    
asked by anonymous 12.01.2017 / 23:19

2 answers

4

To leave WebView on full screen or fullscreen , in English, you must first set both height and width as math_parent . Soon after basically there are two ways to let the device fill in the entire screen space, via XML and programmatically. See:

XML:

No AndroidManifest.xml of your project:

<activity android:name=".ActivityMain"
    android:label="@string/app_name"
    android:theme="@android:style/Theme.NoTitleBar.Fullscreen"/>

Programmatically:

In activity you want to be FULLSCREEN :

public class ActivityMain extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // removendo o título
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
        setContentView(R.layout.main);
    }
}

As also specified in the good user interface documentation, there is a technique called available from the KitKat version of Android.

See the image:

Formoredetails,readmore in the documentation .

    
13.01.2017 / 03:59
0

EDITED:

    <FrameLayout             
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
     android:layout_height="match_parent">

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


<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />

</FrameLayout>

I used your own "TelaCheia" in Manisfest and it worked. I needed to remove that part     getSupportActionBar (). hide (); // here the magic REMOVES THE TITLE BAR     getWindow (). setFeatureInt (Window.FEATURE_PROGRESS, Window.PROGRESS_VISIBILITY_ON);

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/TelaCheia"> <<<<<<<<<<<<<<<=========
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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