简体   繁体   English

加载android webview的最简单方法

[英]simplest way to load android webview

what is the simplest way to load android webview? 加载android webview最简单的方法是什么?

I have already specified webview in the activity layout, how can i load a website on it while running the emulator. 我已经在活动布局中指定了webview,如何在运行模拟器时加载网站。 I have had many problems with resources not identified and the main_activity.out.xml files have been giving me troubles. 我遇到了许多未识别资源的问题,而main_activity.out.xml文件给我带来了麻烦。 A simple webview to load a webpage would be nice. 加载网页的简单webview会很不错。

... ...

<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). 您正在获取main_activity.out.xml因为您正在尝试编译Xml文件(main_activity.out.xml具有焦点并且您单击了运行)。 In general if this error happens you have to 通常,如果发生此错误,则必须执行此操作

  1. Delete the xxx.out.xml 删除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 在src /中打开任何.java文件,双击文件,使其具有焦点,光标在那里
  3. Run your project and everything should be OK now 运行你的项目,一切都应该好了

to load WebView you have to declare your webview component in your xml 要加载WebView,您必须在xml中声明webview组件

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

and then in your activity in onCreate() method call 然后在你的活动中onCreate()方法调用

// 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 = (WebView)findViewById(R.id.webView1);
webview.loadUrl("http://stackoverflow.com/");

Greets Flo 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. main_activity.out.xml已创建,可能是因为您在打开main_activity.xml时按下了Eclipse上的运行按钮。 Eclipse tryed to compile your xml and not your application. Eclipse尝试编译你的xml而不是你的应用程序。

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: 为了最好地管理你的android项目中的webview,只需阅读文档:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM