Hide the Webview address bar

Asked

Viewed 1,151 times

2

How I needed to develop an app like WebApp, followed a tutorial and succeeded (the tutorial used Android Studio IDE 1.0.2). The application works satisfactorily, however there is a detail that I know that this type of application should not present: 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? Would there be a way for the bar not to appear during the display of the site? I have searched several places on the Web but the information is always from previous versions and the project structure does not equal that of 1.4.1. Thanks in advance for the help!!!

imagem 1 imagem 2

My activity_main.xml file

<?xml version="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 file content_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"
    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);
                }
            }
  • I can’t see the images. Could you post part of the implementation code? You’re using the webView component to render your webapp?

  • Hello Diego. Thanks for your attention! I don’t know if I sent the images correctly (in the body of the text) because I can view them here. I suspect, in my little knowledge of Studio, that the point is in the layout. And yes, I am using the webView component. I am sending the codes of the layout activity_main.xml and content_main.xml, in addition to Myappwebviewclient for Voce take a look... thank you very much!

  • Hello Diego. Could you see the images? Did you see the condition I sent? abs

2 answers

1

Add this to disable the address bar:

WebView.setWebViewClient(new WebViewClient());
  • Hello Otto . Thanks for the reply .. but that line of code is already in my Mainactivity.java. Since you did not indicate where it would be inserted, are you in the right place? Thank you and abs

  • Hello Otto. You are in the right place?

  • @Robertogomes did not identify this line in his code

  • Hello Otto. Thank you for your attention. The command line you indicated is in Mainactivity.java. I published the code for you to give your opinion. Thank you!

0

Try to insert into Androidmanifest.xml, within the Activity where he owns the webview:

<activity
.
.
.
android:theme="android:style/Theme.Light.NoTitleBar.Fullscreen"
     ou
android:theme="@android:style/Theme.NoTitleBar"
>
</activity>
  • Thanks Rodrigo. I’ll try ! Thanks! Hug!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.