How to remove url bar and buttons from a webview browser

Asked

Viewed 310 times

-1

Hello, I’m new to Kotlin and I’m using a Project in webview to mirror a website in the App.
However, the only page that comes perfect is the home, the external links the App uses a Webview Browser.
I would like to hide the url bar of this Browser or if possible, pull the same external links is pulled home.

Mainactivity.kt

package org.quaestio.kotlinconvertedwebview

import android.annotation.SuppressLint
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.KeyEvent
import android.webkit.WebView
import android.webkit.WebViewClient
import kotlinx.android.synthetic.main.activity_webview.*

class MainActivity : AppCompatActivity() {

@SuppressLint("SetJavaScriptEnabled")
override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)

    setContentView(R.layout.activity_webview)

    val mWebView = findViewById<WebView>(R.id.webview)

    val webSettings = mWebView.settings
    webSettings.javaScriptEnabled = true
    mWebView.loadUrl(getString(R.string.website_url))
    mWebView.webViewClient = HelloWebViewClient()
    WebView.setWebContentsDebuggingEnabled(false)

}


private inner class HelloWebViewClient : WebViewClient() {

    override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
        if (Uri.parse(url).host == getString(R.string.website_domain)) {
            return false
        }
        val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
        startActivity(intent)
        return true
    }

    override fun onPageFinished(view: WebView, url: String) {
        // TODO Auto-generated method stub
        super.onPageFinished(view, url)
    }

}

override fun onKeyDown(keyCode: Int, event: KeyEvent): Boolean {
    if (keyCode == KeyEvent.KEYCODE_BACK && webview.canGoBack()) {
        webview.goBack()
        return true
    }
    return super.onKeyDown(keyCode, event)
}

Androidmanifest.xml

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

<uses-feature
    android:name="android.hardware.touchscreen"
    android:required="false" />

<application
    android:allowBackup="false"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter
            android:autoVerify="true"
            tools:targetApi="m">
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />

            <data
                android:host="smb-django.herokuapp.com/"
                android:scheme="https://smb-django.herokuapp.com/" />
        </intent-filter>
    </activity>
    <meta-data
        android:name="android.webkit.WebView.EnableSafeBrowsing"
        android:value="true" />
</application>

Thank you so much for anyone who can help me in any way.

  • To hide the bar you can use the method shouldOverrideURLLoading() webView. The button I no longer know.

2 answers

-2


What I really needed was to access external links within the app itself without calling a browser to open it. solved this problem with the Project. Thank you all for your help :)

-2

Some factors may cause this behavior, one of them is the version of the API that is running your Webview, check the version of the API. But some settings can help resolve this behavior, such as:

    mWebView.webViewClient = WebViewClient()
    mWebView.settings.setAppCacheEnabled (true)
    mWebView.settings.javaScriptEnabled = true
    mWebView.settings.loadWithOverviewMode = true
    mWebView.settings.allowFileAccess = true
    mWebView.settings.allowContentAccess = true

Browser other questions tagged

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