How to open webpage in Android Studio (WebView Example)




Your xml file should be like this:
<?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" 
    android:layout_gravity="center">

    <WebView
        android:id="@+id/webView1"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center" />

</LinearLayout>
Your Java file should be like this:
public class WebViewSampleActivity extends Activity {
     WebView wb;
    private class HelloWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            return false;
        }
    }
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);      
        wb=(WebView)findViewById(R.id.webview);        
        wb.getSettings().setJavaScriptEnabled(true);
        wb.getSettings().setLoadWithOverviewMode(true);
        wb.getSettings().setUseWideViewPort(true);
        wb.getSettings().setBuiltInZoomControls(true);
        wb.getSettings().setPluginState(WebSettings.PluginState.ON);
        wb.loadUrl("http://www.examplefoo.com");        
    }
}
Use the following in your manifest after <uses-sdk><uses-sdk/>:

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

1 comment:

  1. Play Baccarat with the best dealers in UK - FEBCASINO
    Baccarat is an easy game to learn and understand, septcasino and it is a popular one at FEBCASINO. Read 인카지노 our exciting casino review and try the games for 바카라사이트 free!

    ReplyDelete

Pages