关闭

Android实现Windows风格的Dialog

标签: Dialog对话框Android实例
810人阅读 评论(0) 收藏 举报
分类:

1.主要的类源码

package com.example.dialogwindows;

import android.net.Uri;
import android.os.Bundle;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.Toast;

/**
 * Title: DialogWindows
 * Description: Windows风格的dialog
 * Company: Weicky
 * @author 许助云
 * @date 2015-7-10
 */
public class DialogWindows extends Activity {

	private Button mainbtn;
	private View CustomView;

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		mainbtn = (Button) findViewById(R.id.mainbtn);
		mainbtn.setOnClickListener(new OnClickListener() {

			public void onClick(View v) {

				Builder builder = myBuilder(DialogWindows.this);
				final AlertDialog dialog = builder.show();
				// 点击屏幕外侧,dialog不消失
				dialog.setCanceledOnTouchOutside(false);
				// 监听dialog里的button
				/*
				 * 监听btn发邮件
				 */
				Button ortherbtnemil = (Button) CustomView
						.findViewById(R.id.ortherbtnemil);
				ortherbtnemil.setOnClickListener(new OnClickListener() {
					public void onClick(View v) {

						Toast.makeText(DialogWindows.this, "发邮件给作者",
								Toast.LENGTH_SHORT).show();
						Intent i = new Intent(Intent.ACTION_SEND);
						// i.setType("text/plain"); //模拟器请使用这行
						i.setType("message/rfc822"); // 真机上使用这行
						i.putExtra(Intent.EXTRA_EMAIL,
								new String[] { "hgncxzy@qq.com" });
						i.putExtra(Intent.EXTRA_SUBJECT, "windows风格dialog反馈");
						i.putExtra(Intent.EXTRA_TEXT, "内容");
						startActivity(Intent.createChooser(i, "选择应用"));
						dialog.dismiss();
					}
				});
				/*
				 * 监听btn访问博客
				 */
				Button ortherbtnweb = (Button) CustomView
						.findViewById(R.id.ortherbtnweb);
				ortherbtnweb.setOnClickListener(new OnClickListener() {
					public void onClick(View v) {

						Toast.makeText(DialogWindows.this, "访问博客",
								Toast.LENGTH_SHORT).show();
						Uri uri = Uri.parse("http://blog.csdn.net/jdfkldjlkjdl");
						Intent intent = new Intent(Intent.ACTION_VIEW, uri);
						startActivity(intent);
						dialog.dismiss();
					}
				});
				/*
				 * 监听imgbtn关闭dialog
				 */
				ImageButton customviewtvimgCancel = (ImageButton) CustomView
						.findViewById(R.id.customviewtvimgCancel);
				customviewtvimgCancel.setOnClickListener(new OnClickListener() {
					public void onClick(View v) {

						dialog.dismiss();
					}
				});
			}
		});
	}

	protected Builder myBuilder(DialogWindows dialogWindows) {

		final LayoutInflater inflater = this.getLayoutInflater();
		AlertDialog.Builder builder = new AlertDialog.Builder(dialogWindows);
		CustomView = inflater.inflate(R.layout.customview, null);

		return builder.setView(CustomView);
	}

}
效果图如下:

源码下载 链接:http://pan.baidu.com/s/1i3gYrYl 密码:btlb

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:458447次
    • 积分:7770
    • 等级:
    • 排名:第2685名
    • 原创:304篇
    • 转载:108篇
    • 译文:0篇
    • 评论:52条
    个人联系方式
    加入我的QQ群
    文章分类
    最新评论