Hide the WebView address bar

2

As I needed to develop an application of type WebApp , I followed a tutorial and I was successful (the tutorial used IDE Android Studio 1.0.2). The application works satisfactorily, but there is one detail I know this type of application should not display: The Address bar above all pages of the site (image) . I used the latest version of Android Studio ( 1.4.1 ). Could someone help me solve this problem? Is there a way the bar does not appear during the website display? I have already searched on several web sites but the information is always from previous versions and the project structure does not match 1.4.1. Thanks in advance for the help !!!

Myactivity_main.xmlfile

<?xmlversion="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
    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"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">

    <android.support.design.widget.AppBarLayout  android:layout_height="wrap_content"
        android:layout_width="match_parent" android:theme="@style/AppTheme.AppBarOverlay">

    </android.support.design.widget.AppBarLayout>

<include layout="@layout/content_main" />

My content_main.xml file

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:showIn="@layout/activity_main"
    tools:context=".MainActivity">


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

</RelativeLayout>

My MyAppWebViewClient.java file

package xxxx.wordpress;

import android.content.Intent;
import android.net.Uri;
import android.webkit.WebView;
import android.webkit.WebViewClient;

/**
 * Created by Beto on 04/11/2015.
 */
//nona insercao de codigo apos MyAppWebViewClient
public class MyAppWebViewClient extends WebViewClient {

//criacao de classe e oitava insercao de codigo
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if(Uri.parse(url).getHost().endsWith("xxx.com.br/wp")) {
            return false;
        }

        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
        view.getContext().startActivity(intent);
        return true;

    }


}

My MainActivity.java file

            import android.os.Bundle;
            import android.support.design.widget.FloatingActionButton;
            import android.support.design.widget.Snackbar;
            import android.support.v7.app.AppCompatActivity;
            import android.support.v7.widget.Toolbar;
            import android.view.View;
            import android.view.Menu;
            import android.view.MenuItem;
            import android.webkit.WebSettings;
            import android.webkit.WebView;
            import android.webkit.WebViewClient;

            public class MainActivity extends AppCompatActivity {


            private WebView mWebView;

                @Override
                protected void onCreate(Bundle savedInstanceState) {
                    super.onCreate(savedInstanceState);
                    setContentView(R.layout.activity_main);
                    mWebView = (WebView) findViewById(R.id.activity_main_webview);

                    // Enable Javascript
                    WebSettings webSettings = mWebView.getSettings();

                    webSettings.setJavaScriptEnabled(true);
                    mWebView.loadUrl("http://xxx.com.br/wp");

                    // Force links and redirects to open in the WebView instead of in a browser
                    mWebView.setWebViewClient(new WebViewClient());

                    // Stop local links and redirects from opening in browser instead of WebView
                    mWebView.setWebViewClient(new MyAppWebViewClient());

                }

                @Override
                public boolean onCreateOptionsMenu(Menu menu) {
                    // Inflate the menu; this adds items to the action bar if it is present.
                    getMenuInflater().inflate(R.menu.menu_main, menu);
                    return true;
                }

                @Override
                public boolean onOptionsItemSelected(MenuItem item) {
                    // Handle action bar item clicks here. The action bar will
                    // automatically handle clicks on the Home/Up button, so long
                    // as you specify a parent activity in AndroidManifest.xml.
                    int id = item.getItemId();

                    //noinspection SimplifiableIfStatement
                    if (id == R.id.action_settings) {
                        return true;
                    }

                    return super.onOptionsItemSelected(item);
                }
            }
    
asked by anonymous 05.11.2015 / 22:03

2 answers

1

Add this to disable the address bar:

WebView.setWebViewClient(new WebViewClient());
    
06.11.2015 / 18:56
0

Try to insert into AndroidManifest.xml , within activity where you have webview :

<activity
.
.
.
android:theme="android:style/Theme.Light.NoTitleBar.Fullscreen"
     ou
android:theme="@android:style/Theme.NoTitleBar"
>
</activity>
    
26.10.2016 / 13:03