开发者

Help understanding why a webview layout won't load the page

I have the following code that works but doesn't use my layout webscreen.

@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 = ne开发者_如何学Cw WebView(this);
    setContentView(webview);

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

If I change the line setcontentview(webview) to setcontentview(R.layout.webscreen) my layout loads but the web page doesn't.

Sorry I am a newbie.

Kind Regards,

Mike


Try This,

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 file

<?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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜