Android 获取要显示的Web视图
我正在尝试用下面的代码加载webview。我在Android 获取要显示的Web视图,android,webview,Android,Webview,我正在尝试用下面的代码加载webview。我在R.id.webview中的id下面看到了红色的曲线。你知道我需要做什么来解决这个问题吗。推荐的两种解决方案是创建字段和创建常量。但是,两个人都没有工作 谢谢你的帮助 import android.app.Activity; import android.os.Bundle; import android.webkit.WebView; import android.webkit.WebViewClient; public class Grea
R.id.webview
中的id下面看到了红色的曲线。你知道我需要做什么来解决这个问题吗。推荐的两种解决方案是创建字段和创建常量。但是,两个人都没有工作
谢谢你的帮助
import android.app.Activity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class GreatRacksActivity extends Activity {
/** Called when the activity is first created. */
WebView mWebView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mWebView = (WebView) findViewById(R.id.webview);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.loadUrl("http://mysite.com");
mWebView.setWebViewClient(new HelloWebViewClient());
}
private class HelloWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return true;
}}
}
在main.xml布局中需要有一个webview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<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>
在main.xml布局中需要一个webview
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000"
android:orientation="vertical" >
<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的Id。如果您共享版面,将有助于解决此问题 例如: android:id=“@+id/webview” android:layout\u width=“fill\u parent”
android:layout\u height=“fill\u parent”/>您可能在布局中缺少WebView的Id。如果您共享布局,将有助于解决此问题 例如: android:id=“@+id/webview” android:layout\u width=“fill\u parent” android:layout\u height=“fill\u parent”/>在布局文件(main.xml)中是否有WebView(id为WebView)?在布局文件(main.xml)中是否有WebView(id为WebView)?