panthro
panthro

Reputation: 24059

Android Webview - XML?

Is there a way to define a webview in the layout xml rather than in the code.

And if so how? Or is it recommended that it's coded in to an activity?

Upvotes: 5

Views: 17487

Answers (3)

amine
amine

Reputation: 31

and in your code type this :

WebView wv = (WebView)findViewById(R.id.webview);
wv.setWebViewClient(new WebViewClient(){
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        view.loadUrl(url);
        return true;
    }
});
wv.loadUrl("your url here");

Upvotes: 0

Lucian
Lucian

Reputation: 174

Yes as above use the WebView tag:

<WebView android:id="@+id/webview"
android:layout_width="fill_parent" android:layout_height="50dip"/>

A sample application can be found here: http://www.androiddom.com/2011/04/creating-android-calculator-tutorial.html

The author creates a calculator that uses the WebView which is specified in the main.xml layout.

Upvotes: 10

prolink007
prolink007

Reputation: 34554

Yes, use the <WebView /> tag to do this in the xml layout.

Upvotes: 0

Related Questions