简体   繁体   中英

simplest way to load android webview

what is the simplest way to load android webview?

I have already specified webview in the activity layout, how can i load a website on it while running the emulator. I have had many problems with resources not identified and the main_activity.out.xml files have been giving me troubles. A simple webview to load a webpage would be nice.

...

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

You are getting main_activity.out.xml because you are trying to compile Xml files (main_activity.out.xml have the focus and you clicked run). In general if this error happens you have to

  1. Delete the xxx.out.xml
  2. Open any .java file in src/ by double click in the file so it has focus and the cursor is in there
  3. Run your project and everything should be OK now

to load WebView you have to declare your webview component in your xml

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

and then in your activity in onCreate() method call

// get reference to your view
WebView webview = (WebView)findViewById(R.id.myWebView);
// load your WebView content
webview.loadUrl("http://google.com/");

Simplest way?

Get access to WebView via

WebView webview = (WebView)findViewById(R.id.webView1);
webview.loadUrl("http://stackoverflow.com/");

Greets Flo

main_activity.out.xml has been created maybe beacuse you pressed the run button on Eclipse while your main_activity.xml was opened. Eclipse tryed to compile your xml and not your application.

To do that right, try to select the reference of your application inside the project explorer on the left and then click the Run button.

In order to manage at best the webview in your android project, just read the documentation:

http://developer.android.com/guide/webapps/webview.html

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