现需:一android中的webview的使用的demo,
最好是提供完整的,可运行的例子,哪位帮帮忙,thanks

解决方案 »

  1.   

    有哪位可分享些资料吗 thanks
      

  2.   

    webview就是把一个网页内容直接显示在你的Activity里呀
      

  3.   

    多谢楼上的
    现需:一android中的webview的使用的demo,
    最好是提供完整的,可运行的例子,哪位帮帮忙,thanks
      

  4.   


        <WebView
            android:id="@+id/webview"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_x="0.1dip"
            android:layout_y="0.1dip" 
            android:layout_weight="1.0" />package com.android.webview;import android.app.Activity;
    import android.app.ProgressDialog;
    import android.os.Bundle;
    import android.os.Handler;
    import android.webkit.WebChromeClient;
    import android.webkit.WebView;
    import android.webkit.WebViewClient;public class WebViewTestActivity extends Activity {
        /** Called when the activity is first created. */
    WebView wv;
    ProgressDialog pd;
    Handler handler;
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            
            init();
            loadUrl(wv, "http://www.baidu.com/");
            
            handler=new Handler(){
         public void handleMessage(android.os.Message msg) {
        
         if(Thread.currentThread().isInterrupted()){
         switch(msg.what){
         case 0:
         pd.show();
         break;
         case 1:
         pd.hide();
         break;
         }
         }
         };
         };
        }
        
        public void init(){
         wv=(WebView) findViewById(R.id.webview);
         //可用js
         wv.getSettings().setJavaScriptEnabled(true);
         //滚动条风格,为0就是不给滚动条留空间,滚动条覆盖在网页上
         wv.setScrollBarStyle(0);
         wv.setWebViewClient(new WebViewClient(){
         @Override
         public boolean shouldOverrideUrlLoading(WebView view, String url) {
         loadUrl(view, url);
         return super.shouldOverrideUrlLoading(view, url);
         }
         });
        
         wv.setWebChromeClient(new WebChromeClient(){
         @Override
         public void onProgressChanged(WebView view, int newProgress) {
         if(newProgress==100){
         handler.sendEmptyMessage(1);
         }
         super.onProgressChanged(view, newProgress);
         }
         });
        
         pd=new ProgressDialog(WebViewTestActivity.this);
         pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
         pd.setMessage("数据加载中,请稍候...");
        }
        
        public void loadUrl(final WebView webView,final String url){
         new Thread(){
         @Override
         public void run() {
         handler.sendEmptyMessage(0);
         webView.loadUrl(url);
         }
         }.start();
        }
    }
      

  5.   

    多谢五楼,程序可运行,
    可baidu的页面没出来,屏上提示 '找不到网页'
    什么原因,怎么处理?
      

  6.   

    可以加我好友,一起探讨Android问题。
      

  7.   

    你说的网络是什么网络?
    (这程序我是在手机上运行的,现手机上用手机卡上网的,并在手机浏览器中可进入baidu的。)
      

  8.   

    有没有报什么异常或者warning、什么的  你加那个网络permission了
      

  9.   

    加了呀
    AndroidManifest.xml 如下
    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.example.android.apis"
          android:versionCode="1"
          android:versionName="1.0">
      <uses-sdk android:minSdkVersion="10" />    <application android:icon="@drawable/icon" android:label="@string/app_name">
            <activity android:name=".WebViewTestActivity"
                      android:label="@string/app_name">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>    </application>
          <uses-permission android:name="android.permission.INTERNET"/>
    </manifest>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"
        >
    <TextView  
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:text="@string/hello"
        />
    <WebView
      android:id="@+id/webview"
      android:layout_width="fill_parent"
      android:layout_height="fill_parent"
      android:layout_x="0.1dip"
      android:layout_y="0.1dip"  
      android:layout_weight="1.0" /></LinearLayout>你加我q : 350038760
      

  10.   

    你的项目文件,在我这边运行出来了,可baidu的页面还是没出来,还是提示“找不到网页”
      

  11.   

    哦,可以运行了,baidu页面也出来了,是手机需设置wan,我把手机卡网络关了,再连办公室的无线wan就好了。