Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android AlertDialog 對話框添加、屬性

Android AlertDialog 對話框添加、屬性

編輯:關於Android編程

package gongzibai.co.cc;

import android.app.Activity;
import android.app.Dialog;
import android.os.Bundle;

public class ProgressBarActivity extends
  Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(
   Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.main);
 
 
  Dialog dialog = new Dialog(this);
  dialog.setTitle("loveyou");
  //對話框設置 視圖,新建一個布局main1
  dialog.setContentView(R.layout.main1);
  //觸屏對話框以外區域,對話框消失
  dialog.setCanceledOnTouchOutside(true);
  dialog.show();
 }
}


-----------------AlertDialog
final DialogInterface.OnClickListener closeDialog = new

DialogInterface.OnClickListener() {

   @Override
   public void onClick(
     DialogInterface dialog,
     int which) {
    // TODO Auto-generated method stub
    dialog.cancel();

   }
  };

-------------AlertDialog屬性   www.2cto.com
 AlertDialog.Builder builder = new AlertDialog.Builder(
        ProgressBarActivity.this);
      builder.setIcon(R.drawable.ic_launcher);
      builder.setTitle("loveyou");
      builder.setMessage("great to see you");
      builder.setNegativeButton(
        "NO",
        closeDialog);
      builder.setPositiveButton(
        "ok",
        closeDialog);
      builder.setNeutralButton(
        "取消",
        closeDialog);
      builder.create()
        .show();


 

作者:gongzibai
  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved