Disable address bar in Android webview

前端 未结 4 747
遥遥无期
遥遥无期 2020-12-03 09:30

How do disable and hide the address bar from a WebView?

相关标签:
4条回答
  • 2020-12-03 10:01

    Finally I Try with this. Its worked for me..

    Here is the working code

    private WebView webview ;   
    @Override
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_ebook);
    
        //webview use to call own site
        webview =(WebView)findViewById(R.id.webView);
    
        webview.setWebViewClient(new WebViewClient());          
        webview .getSettings().setJavaScriptEnabled(true);
        webview .getSettings().setDomStorageEnabled(true);      
        webview.loadUrl("http://www.google.com"); 
    }
    

    and your entire main.xml(res/layout) look should like this:

    <WebView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/webView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        />
    

    don't go to add layouts.

    0 讨论(0)
  • 2020-12-03 10:02

    There is no address bar in a WebView.

    If you think you have a WebView, and you see an address bar, that is not your WebView. Rather, you are looking at the Browser application. Most likely, the URL you told the WebView to load did a redirect, and you did not intercept that redirect using a WebViewClient and shouldOverrideURLLoading().

    0 讨论(0)
  • 2020-12-03 10:10
    webview.setWebViewClient(new WebViewClient());  
    

    solved the problem for me..

    0 讨论(0)
  • 2020-12-03 10:12

    Adding myView.setWebViewClient(new WebViewClient()); disabled the address bar for me.

    import android.webkit.WebView;
    import android.webkit.WebViewClient;
    
    ...
    
    WebView myView = findViewById(R.id.myExampleView);
    myView.setWebViewClient(new WebViewClient());
    myView.getSettings().setJavaScriptEnabled(true);
    myView.loadUrl("https://www.stackoverflow.com");
    

    XML Snippet

    <WebView android:id="@+id/myExampleView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:keepScreenOn="true"
        android:gravity="center" />
    

    source: (Japanese site): http://www.techdoctranslator.com/android/webapps/webview

    0 讨论(0)
提交回复
热议问题