2013-02-17 45 views
-1

我的測試手機版本是Android api 2.1。 我想知道webview是在api 2.1中運行的。因此,我試圖在代碼下面,但它不能運行。不是'Android API Version 2.1'有webview嗎?

調色板(當您可以看到activity_main.xml GraphicalLayout)沒有webview控件。但是,4.0版本有它。 所以我輸入XmlCode ,但它顯示消息「以下類找不到: - 網頁視圖(修復構建路徑,編輯XML)」

你知道如何在API 2.1操作的WebView ?

p.s)我試着重新啓動eclipse和項目乾淨。

<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; 
    } 
} 
+0

顯示LogCat,您得到的錯誤是什麼。 – 2013-02-17 13:26:41

回答

7

佈局XML區分大小寫。您應該使用的正確XML如下所示:

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

謝謝你的幫助,我解決了這個問題。但是,在Eclipse中的圖形Layout Palette Compisite中看不到控件。你知道他的理由嗎?我正在使用Eclipse juno SDK版本:4.2.0。 – user2080447 2013-02-18 16:19:21

+0

@ user2080447,也許你應該在另一個問題上提出這個問題。我根本沒有使用圖形佈局,所以我不知道。但如果它有效,我的回答對你有幫助,那麼你可以選擇它作爲接受的答案(帶有複選標記)。祝你好運! – Shade 2013-02-18 19:28:02

相關問題