[英]Issue Creating simple WebView Android
OK - so I typically develop for iOS but have a client who needs a hand in a pinch. 好的-所以我通常为iOS开发,但是有一个需要帮助的客户。
I followed a tutorial, which was very straightforward and helpful. 我遵循了一个教程,该教程非常直接且非常有用。 I created everything as it had asked me to (or maybe I didn't - which is why I'm here). 我创建了它要求我做的所有事情(也许我没有,这就是为什么我在这里)。
Any help would be greatly appreciated. 任何帮助将不胜感激。 We are really in a bind here! 我们真的在这里束缚!
You're welcome to come in over join.me as well and take a look. 也欢迎您也加入join.me看看。 I think it could be something incredibly simple that I am too ignorant/inexperienced with this platform to see. 我认为对这个平台我太无知/缺乏经验,这可能是一件非常简单的事情。
http://www.tutorialspoint.com/android/android_webview_layout.htm http://www.tutorialspoint.com/android/android_webview_layout.htm
The issue could be very simple. 这个问题可能非常简单。 On these lines, I am getting errors which Eclipse will not override: 在这些行上,我遇到了Eclipse无法覆盖的错误:
setContentView(R.layout.activity_main);
field = (EditText)findViewById(R.id.urlField);
browser = (WebView)findViewById(R.id.webView1);
Error is "R cannot be resolved to a variable 错误是“ R无法解析为变量
Here is my MainActivity.java 这是我的MainActivity.java
package com.example.WebView;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity {
private EditText field;
private WebView browser;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
field = (EditText)findViewById(R.id.urlField);
browser = (WebView)findViewById(R.id.webView1);
browser.setWebViewClient(new MyBrowser());
}
public void open(View view){
String url = field.getText().toString();
browser.getSettings().setLoadsImagesAutomatically(true);
browser.getSettings().setJavaScriptEnabled(true);
browser.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
browser.loadUrl("http://www.magiktab.com/app");
}
private class MyBrowser extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl("http://www.magiktab.com/app");
return true;
}
}
}
Here is my activity_main.xml 这是我的activity_main.xml
<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"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<EditText
android:id="@+id/urlField"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/textView1"
android:layout_centerHorizontal="true"
android:ems="10" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/urlField"
android:layout_centerHorizontal="true"
android:onClick="open"
android:text="@string/browse" />
<WebView
android:id="@+id/webView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_alignParentBottom="true"
android:layout_below="@+id/button1" />
</RelativeLayout>
And of course, my manifest 当然,我的清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.webview"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.webview.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>
This may happen when your application package name is different from the activity package name; 当您的应用程序包名称与活动包名称不同时,可能会发生这种情况;
import com.your.app.package.name.R;
usually helps. 通常会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.