關於Android載入網頁的一些問題

來源:互聯網
上載者:User

  大家都知道Android可以載入網頁,但是網上給的一些例子都是html的,所以最近有被誤導到,再次分享一下心得。

  如果是載入你自己網站或是空間上的網頁時,不要直接載入html格式的,因為當你更換html內容時(地址不變),Android顯示的還是你沒有更改之前的html。所以要想實現動態更改網頁內容,你需要使用web伺服器來提供動態網頁技術,比如jsp,asp之類的。送給需要的朋友。

  這下終於理解動態網頁和靜態網頁的一些區別了,回頭要好好補一下這方面的知識了。

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;
import android.webkit.WebView;
import android.widget.Toast;

public class UnicomActivity extends Activity {

WebView webView;
private static final String URL = "http://60.18.151.202/android.asp";  //不是html哦
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);  
        // 進行全屏  
  
        this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
                WindowManager.LayoutParams.FLAG_FULLSCREEN);  
        setContentView(R.layout.main);
        webView=(WebView) findViewById(R.id.webView01);
   
        webView.loadUrl(URL); 
    }

 
@Override  
   public boolean onKeyDown(int keyCode, KeyEvent event) {  
       if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {  
           dialog();  
           return true;  
       }  
       return true;  
   }  
protected void dialog() {  
       AlertDialog.Builder builder = new Builder( UnicomActivity.this);  
       builder.setMessage("確定要退出嗎?");  
       builder.setTitle("提示");  
       builder.setPositiveButton("確認",  
       new android.content.DialogInterface.OnClickListener() {  
           public void onClick(DialogInterface dialog, int which) {  
               dialog.dismiss();  
               //AccoutList.this.finish();  
               //System.exit(1);  
               android.os.Process.killProcess(android.os.Process.myPid());  
           }  
       });  
       builder.setNegativeButton("取消",  
       new android.content.DialogInterface.OnClickListener() {  
           public void onClick(DialogInterface dialog, int which) {  
               dialog.dismiss();  
           }  
       });  
       builder.create().show();  
   }  
}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.