Android对话框

1.1简单提示框

//简单提示框
    private Dialog Dialog1(){
    	return new AlertDialog.Builder(XXXActivity.this).setTitle("提示").setMessage("提示内容太短").show();
    }


1.2多个按钮提示框

 @Override
    protected Dialog onCreateDialog(int id) {
    	if(id == 1){//两个按钮提示框
    		return new AlertDialog.Builder(XXXActivity.this)
    						.setTitle("提示").setMessage("提示内容太短")
    						.setPositiveButton("确定", new DialogInterface.OnClickListener() {
								
								@Override
								public void onClick(DialogInterface dialog, int which) {
									// TODO Auto-generated method stub
									dismissDialog(1);
								}
							})
							.setNegativeButton("取消", new DialogInterface.OnClickListener() {
								
								@Override
								public void onClick(DialogInterface dialog, int which) {
									// TODO Auto-generated method stub
									dismissDialog(1);
								}
							}).create();
    	}else if(id == 2){//三个按钮提示框
    		return new AlertDialog.Builder(XXXActivity.this)
    					.setTitle("提示").setMessage("哈哈哈哈")
    					.setIcon(R.drawable.ic_launcher)
    					.setPositiveButton("注册", new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								// TODO Auto-generated method stub
								
							}
						})
						.setNeutralButton("找回密码", new DialogInterface.OnClickListener() {
							//注意这里和下面的取消是不一样的setNeutral.....setNegative
							@Override
							public void onClick(DialogInterface dialog, int which) {
								// TODO Auto-generated method stub
								
							}
						})
						.setNegativeButton("取消", new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								// TODO Auto-generated method stub
								
							}
						}).create();
    	}else if(id ==4){ //圆形进度框
    		ProgressDialog dialog =  new ProgressDialog(XXXActivity.this);
    		dialog.setTitle("正在下载歌曲...");
    		dialog.setMessage("请稍候......");
    		return dialog;
    	}
    	
    	return super.onCreateDialog(id);
    }
调用时showDialog(4);


1.3自定义对话框

命名xxxx.xml文件是我们想要自定义的风格

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical" >
	<TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
	     android:layout_marginLeft="20dip" android:layout_marginRight="20dip"
	     android:text="请输入..." android:gravity="left"
	     android:textAppearance="?android:attr/textAppearanceMedium"/>
    <EditText android:id="@+id/testdaysnum"
        android:layout_height="wrap_content" 
        android:layout_width="fill_parent"
        android:layout_marginLeft="20dip"
        android:layout_marginRight="20dip"
        android:scrollHorizontally="true"
        android:autoText="false"
        android:capitalize="none"
        android:gravity="fill_horizontal"
        android:textAppearance="?android:attr/textAppearanceMedium"
        />
	
</LinearLayout>
Activity调用
 //自定义Dialog
        LayoutInflater factory = LayoutInflater.from(XXXActivity.this);
        final View testDialogView = factory.inflate(R.layout.xxxx, null);
        EditText edit_GetDayNum = (EditText)testDialogView.findViewById(R.id.testdaysnum);
        new AlertDialog.Builder(XXXActivity.this)
        .setTitle("提示")
        .setView(testDialogView)
        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
			
			@Override
			public void onClick(DialogInterface dialog, int which) {
				// TODO Auto-generated method stub
				
				Toast.makeText(XXXActivity.this, "请等待...", Toast.LENGTH_LONG).show();
			}
		}).create().show();

1.4圆形进度框
ProgressDialog m_Dialog = ProgressDialog.show(XXXActivity.this, "请等待...", "请稍候....",true);


1.5Toast
Toast.makeText(XXXActivity.this, "请等待...", Toast.LENGTH_LONG).show();

1.6模式对话框
Dialog dialog = new Dialog(XXXActivity.this);
        Window window = dialog.getWindow();
        window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,
        WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
        dialog.show();


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值