Dialog

public class MainActivity extends Activity {

	private Button btn, btn2, btn3;
	private TextView text_ure, text_pass;
	private EditText urename, password;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		Button btn = (Button) findViewById(R.id.btn);
		Button btn2 = (Button) findViewById(R.id.btn2);
		Button btn3 = (Button) findViewById(R.id.btn3);

		btn.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
				switch (arg0.getId()) {
				case R.id.btn:
					AlertDialog.Builder dialog = new Builder(MainActivity.this);
					// 标题
					dialog.setTitle("我是标题");
					// 图片
					dialog.setIcon(R.drawable.hbn);
					// 内容
					dialog.setMessage("我是内容");
					dialog.show();<span style="white-space:pre">	</span>//不要忘记show一下

					break;
				default:
					break;
				}
			}
		});

		btn2.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub

				switch (arg0.getId()) {
				case R.id.btn2:

					AlertDialog.Builder dialog = new Builder(MainActivity.this);
					dialog.setTitle("标题");
					dialog.setMessage("内容");
					dialog.setIcon(R.drawable.navigation_forward);

					dialog.setNegativeButton("确定",
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface arg0,
										int arg1) {
									// TODO Auto-generated method stub

									Toast.makeText(MainActivity.this,
											"点击了确定按钮", 1000);
								}
							});

					dialog.setNeutralButton("取消",
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface arg0,
										int arg1) {
									// TODO Auto-generated method stub

									Toast.makeText(MainActivity.this,
											"点击了取消按钮", 1000);
								}
							});

					dialog.setPositiveButton("详情",
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface arg0,
										int arg1) {
									// TODO Auto-generated method stub
									Toast.makeText(MainActivity.this,
											"点击了详情按钮", 1000);
								}
							});
					dialog.show();

					break;

				default:
					break;
				}
			}
		});

		btn3.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				
				switch (arg0.getId()) {
				case R.id.btn3:
					
					AlertDialog.Builder dialog = new Builder(MainActivity.this);
					
					 View myview = LayoutInflater.from(MainActivity.this)
							.inflate(R.layout.coustum_view, null);
					  urename=(EditText) findViewById(R.id.urename);
					  password=(EditText) findViewById(R.id.password);
					  
					dialog.setView(myview);
					dialog.setMessage("登录界面");
					dialog.setTitle("自定义界面");
					dialog.setNegativeButton("登录",
							new DialogInterface.OnClickListener() {

								@Override
								public void onClick(DialogInterface arg0, int arg1) {
									// TODO Auto-generated method stub
									String str = urename.getText().toString()
											.trim()
											+ "/"
											+ password.getText().toString().trim();
									Toast.makeText(MainActivity.this, str, 1000).show();
								}
							});

					dialog.setNeutralButton("取消",
							new DialogInterface.OnClickListener() {
								@Override
								public void onClick(DialogInterface arg0, int arg1) {
									// TODO Auto-generated method stub
								}
							});
					dialog.show();
					break;
				}
			}
		});
	}
}


btn图



btn2图



btn3图




Android <wbr>Dialog <wbr>系统样式讲解及透明背景
oid <wbr>Dialog <wbr>系统样式讲解及透明背景
Android <wbr>Dialog <wbr>系统样式讲解及透明背景AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_TRADITIONAL);//传统主题

Android <wbr>Dialog <wbr>系统样式讲解及透明背景

AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_HOLO_DARK);//使用深色背景 主题

Android <wbr>Dialog <wbr>系统样式讲解及透明背景


AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_HOLO_LIGHT);//使用浅色背景  主题

Android <wbr>Dialog <wbr>系统样式讲解及透明背景


AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_DEVICE_DEFAULT_DARK);//使用默认设备 深色主题

Android <wbr>Dialog <wbr>系统样式讲解及透明背景

AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);//使用默认设备  色主题

Android <wbr>Dialog <wbr>系统样式讲解及透明背景

//自定义布局 
View layout = getActivity().getLayoutInflater().inflate(R.layout.mydialog,null);
AlertDialog.Builder  dialog  = new AlertDialog.Builder(DialogActivity.this,AlertDialog. THEME_DEVICE_DEFAULT_DARK);
final AlertDialog dialog = builder.create();
dialog.setView(layout);
//透明
Window window = dialog.getWindow(); 
WindowManager.LayoutParams lp = window.getAttributes();
lp.alpha = 0.9f;
window.setAttributes(lp);
。。。
dialog.show();

Android <wbr>Dialog <wbr>系统样式讲解及透明背景



  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值