• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps webview not loaded in app

lye85

Newbie
i have a button and webview on main page, but when i click on button app will redirect me to android internet browser instead of show up website in webview, any expert can help me to figure it out?

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">

<Button
android:id="@+id/button1"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:text="@string/hello_world" />

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

</LinearLayout>

package com.example.app006;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.webkit.WebView;

public class MainActivity extends Activity {

private WebView webView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button)this.findViewById(R.id.button1);

button.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View arg0) {
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
startActivity(i);
}
});

//this.webView = (WebView)this.findViewById(R.id.webView1);
//this.webView.loadUrl("http://themobilemontage.com");
}


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

}
 
Code:
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.google.com"));
                startActivity(i);
cuz that calls the browser.

and the // in front of those two webview lines makes them not work.


you need to setup webview in your intent
 
You need the following within your webview config to allow the url to load within your webview and not a default browser:

webview.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});

reference: WebViewClient | Android Developers
 
no, that makes links you click from inside the webview stay in the webview.

i think he's trying to get the original link to load in the webview.

he has // in front of his webview for some reason. he needs to uncomment those and try.
 
Back
Top Bottom