Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1706707
  • 博文数量: 171
  • 博客积分: 11553
  • 博客等级: 上将
  • 技术积分: 3986
  • 用 户 组: 普通用户
  • 注册时间: 2006-05-25 20:28
文章分类

全部博文(171)

文章存档

2012年(2)

2011年(70)

2010年(9)

2009年(14)

2008年(76)

分类: Java

2009-09-13 10:56:48

本文介绍了如何在Activity中启动一个对话框,对话框不执行任何操作,仅仅将标题(Title)改变为“测试对话框”。对话框是位于onCreateDialog创建。
实现代码:
package com.wanpor;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

/**
 * 创建一个只包含一个按钮的视图
 * 对按钮添加单击事件,单击时启动对话框
 * @author wanpor
 *
 */
public class TransparentDlg extends Activity {
    Button bStartDlg = null;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
       
        //设置按钮的单击回调
        bStartDlg = (Button)findViewById(R.id.Start);
        bStartDlg.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                //显示对话框
                showDialog(0);
            }
           
        });
    }

    /**
     * 对话框在第一次启动时会调用此函数,用于创建对话框
     */
    @Override
    protected Dialog onCreateDialog(int id) {
        AlertDialog.Builder mydlg = new AlertDialog.Builder(this);
        mydlg.setTitle("对话框测试");
        AlertDialog alert = mydlg.create();
        //返回生成的对话框
        return alert;
       
    }
   
   
}
布局文件

    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
   


阅读(1613) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~