Question

My test phone version is Android api 2.1 . And I want to know webview is operated in api 2.1. thus, I'm trying to below code, but it doesn't operated.

The Palette(When you could see the activity_main.xml GraphicalLayout) didn't have webview control. but, 4.0 version had it. So I typed in XmlCode, but It is shown message that 'The following classes could not be found: - webview (Fix Build Path, Edit XML)'

Do you know how to operate webview in api 2.1?

p.s) I tried restart eclipse and project clean.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true"
    android:text="@string/hello_world"
    tools:context=".MainActivity" />
<webview android:id="@+id/webview" android:layout_width="fill_parent" android:layout_height="fill_parent">

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.webkit.WebView;
public class MainActivity extends Activity {
    WebView webview;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        webview = (WebView) findViewById(R.id.webview);
        webview.getSettings().setJavaScriptEnabled(true);
        webview.loadUrl("http://google.com");  
    }
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }
}
Was it helpful?

Solution

The layout XML is case-sensitive. The correct XML you should be using is like this:

<WebView
    android:id="@+id/webview"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" />

OTHER TIPS

The docs (http://developer.android.com/reference/android/webkit/WebView.html) say that WebView has been available since API 1.

You probably have some other problem - the APIs have supported this since the beginning.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top