简体   繁体   中英

Hide webview when a url is called android studio

I've a problem and i don't know how to solved it.

I made a little program with a switch button. When the button is switched on then a url is been send and when switch is off it sends another url.

The code works but when the link is sended it opens a webview.

public void onToggleClicked(View view) {
        // Is the toggle on?
        boolean on = ((ToggleButton) view).isChecked();

        if (on) {
            // Enable vibrate
            Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
            myWebLink.setData(Uri.parse("https://xxxxxxx));

            startActivity(myWebLink);
            //WebView.setVisibility(View.GONE);

        } else {
            // Disable vibrate
            Intent myWebLink = new Intent(android.content.Intent.ACTION_VIEW);
            myWebLink.setData(Uri.parse("https://xxxxxx"));

            startActivity(myWebLink);
        }
    }

is it possible to make it so that i don't se the webview, so that my program always stays in front.

i tryed WebView.setVisibility(View.GONE); but by setVisibilty i get a error.

Please can somebody help me with this?

You're starting a new activity, so this implies "opening the webview" (in this case, will be a browser). You could use a real WebView , but I suggest you to use Retrofit or some other library like it to make the HTTP requests without having to resort to a complex object like a WebView .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM