webview和android eclipse
我有一个HTML5网页,我想使用Android DSK的webview 这是我的androidmanifest.xmlwebview和android eclipse,android,webview,Android,Webview,我有一个HTML5网页,我想使用Android DSK的webview 这是我的androidmanifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.myfirstapp" android:versionCode="1" android:ver
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myfirstapp"
android:versionCode="1"
android:versionName="1.0" >
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.myfirstapp.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
但是我应该把这些代码放在哪里呢?在新文件中?我已经尝试了很多方法,但都没有成功。从MainActivity.java文件调用:
以下是一个很好的示例参考:
只需将这两行WebView代码放在活动的onCreate方法中,在setContentView下方…@Adrian Diaz查看发布的解决问题的解决方案。abhi,好的,你可以发布一个示例代码,我可以把它放在哪里file@AdrianDiaz然后在这个包com.example.myfirstapp下添加MainActivity.java,并添加发布的内容。请使用参考链接查看完整示例。还有一个下载链接的例子。“活动不能作为类型解析,网络视图不能作为类型解析,@AdrianDiaz请参见我的编辑。”。您需要为此导入所需和使用的软件包。好的,patrik,我认为它现在可以工作了,但最后一个错误是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="@string/hello_world" />
<WebView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</RelativeLayout>
WebView myWebView = (WebView) findViewById(R.id.webview);
myWebView.loadUrl("http://www.example.com");
package com.example.myfirstapp;
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
public class MainActivity extends Activity {
private WebView webView;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymain);
webView = (WebView) findViewById(R.id.webview);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadUrl("http://www.google.com");
}
}