2011-04-27 28 views
3

我有以下代碼可以使用,但不使用我的佈局網頁。幫助理解爲什麼webview佈局不會加載頁面

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.webscreen); 
    String turl = getIntent().getStringExtra(URL); 
    Log.v(TAG, "Recipe url = "+turl); 

    WebView webview = new WebView(this); 
    setContentView(webview); 

    webview.clearCache(true); 
    webview.loadUrl(turl); 

如果我更改線路的setContentView(web視圖)來的setContentView(R.layout.webscreen)我的佈局,但加載網頁沒有。

對不起,我是一個新手。

親切的問候,

邁克

回答

3

試試這個,

public class Main extends Activity { 
    WebView webview1; 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.webview); 

     webview1 = (WebView)findViewById(R.id.webview01); 

     webview1.getSettings().setJavaScriptEnabled(true); 
     webview1.getSettings().setJavaScriptCanOpenWindowsAutomatically(true); 

     webview1.getSettings().setBuiltInZoomControls(true); 
     webview1.setInitialScale(50); 
     webview1.loadUrl("http://www.mywebsite.com/"); 

    } 
} 

xml文件

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" android:layout_height="fill_parent"> 
<ScrollView android:layout_width="fill_parent" android:layout_height="fill_parent" android:scrollbars="horizontal"> 
<WebView android:layout_marginTop="60sp" android:id="@+id/webview01" android:layout_width="fill_parent" android:layout_height="fill_parent"/> 

</ScrollView> 
</LinearLayout> 
+0

曾爲..謝謝你.. – Mike 2011-04-27 06:09:13

+0

謝謝'webview1.getSettings() .setJavaScriptCanOpenWindowsAutomatically(真)'。現在顯示Lenovo Vibe Z2的支付框架。 – CoolMind 2017-09-22 16:25:34