Reputation: 24059
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
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
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