开发者

WebView Using Problem in Android

开发者 https://www.devze.com 2023-01-28 06:49 出处:网络
When I press Load Url button on my Activity, it starts a new browser instead of displaying the content in the WebView widget in the default Activity.

When I press Load Url button on my Activity, it starts a new browser instead of displaying the content in the WebView widget in the default Activity.

Here is the res/layout/main.xml :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="wrap_content" android:layout_height="wrap_content">
        <Button android:layout_width="wrap_content"
            android:layout_height="wrap_content" android:text="Load Yahoo"
            android:id="@+id/buttonLoadYahoo"></Button>
    </LinearLayout>
   开发者_StackOverflow社区 <LinearLayout android:id="@+id/LinearLayout02"
        android:layout_width="match_parent" android:layout_height="fill_parent">
        <WebView android:id="@+id/browserMine" android:layout_height="fill_parent"
            android:layout_width="fill_parent"></WebView>
    </LinearLayout>
</LinearLayout>

And also my src/com/tariknotebook/NoteBook.java file content :

package com.tariknotebook;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;

public class NoteBook extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button buttonLoadYahoo = (Button) findViewById(R.id.buttonLoadYahoo);
        final WebView web = (WebView) findViewById(R.id.browserMine);
        buttonLoadYahoo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                web.loadUrl("http://www.seslisozluk.com");
            }
        }); 
    }
}


You need to implement the WebViewClient and set it to your WebView class. You would also need to set javascript enabled.

mWebView.getSettings().setJavaScriptEnabled(true);

Check this example and the steps from 6.

http://developer.android.com/resources/tutorials/views/hello-webview.html

0

精彩评论

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