1.直接构造Dialog实例,此对话框显示的是当前的电池状态
final Dialog d = new Dialog(GetBetteryActivity.this);
d.setTitle("系统消息");
d.setContentView(R.layout.getbattery_dialog);//设置Dialog的视图
//这两句话是呈现背景模糊的效果
Window window = d.getWindow();
window.setFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND,WindowManager.LayoutParams.FLAG_BLUR_BEHIND);
//取得Dialog中的组件textView,做一些显示
TextView myTextView =
(TextView) d.findViewById (R.id.myTextView_battery);
myTextView.setText("电池电量"+intLevel*100/intScale+"%");
//Dialog视图里有一个Button,取得这个Button,点击的时候注销接收广播
Button myButton = (Button) d.findViewById(R.id.myButton_battery);
myButton.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
unregisterReceiver(mBatInfoReceiver);
d.dismiss();
}});
d.show();//最后显示这个对话框。
2.利用AlertDialog.Builder构造对话框
final String[] str = {"Monday","Tuesday"};
new AlertDialog.Builder(ActivityMain.this)
.setTitle("选择日期")
.setItems(
str,new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog, int which) {
new AlertDialog.Builder(ActivityMain.this)
.setMessage("您选择的是:"+str[which]) .setPositiveButton("确认",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,
int which) { }
})
.setNeutralButton("取消",
new DialogInterface.OnClickListener(){
public void onClick(DialogInterface dialog,
int which) { }
})
.show();//显示点击第一个对话框之后产生的第二个对话框
}
})
.show();//显示第一个对话框
分享到:
相关推荐
安卓使用弹框做到倒计时的用法,分别使用MaterialDialog、AlertDialog来做了一个小demo
自定义对话框LoadingDialog和Toast,可以添加Gif动画的Dialog,喜欢的自行下载!
android倒计时器的demo,采用CountDownTimer
AlertDialog,分别弹出对话框、单选框、对选对话框,并标有注释适合初学者,AlertDialog.Builder builder=new Builder(this);
博客链接http://blog.csdn.net/qq_31390699/article/details/79094499 自定义dialog,封装点击事件,设置对话框文案,弹出动画,设置位置等
NULL 博文链接:https://2528.iteye.com/blog/1123944
仿ios苹果样式的alertdialog,还有带有计时器的dialog,直接调用使用, 封装好了
android dialog 包括alertdialog 和progressdialog 还有自定义通过window 显示的界面很美观。
Android之修改AlertDialog对话框及使用系统Holo风格
Dialog对话框的使用 (progressDialog、AlertDialog、点击不消失、进度条) 具体可参考我文章:https://blog.csdn.net/qq_28056277/article/details/84591086 【更新-->下载所需积分太高,更改为固定分值了】
自定义实现Dialog、AlertDialog,建议先看博客:UI效果(2): 自定义Dialog,然后再决定是否下载。
主要使用了AlertDialog、ActionSheetDialog来实现,AlertDialog的方法和android中自带的用法相似,ActionSheetDialo的用法和AlertDialog差不多,基本的使用思路是:获取Dialog布局、获取自定义Dialog布局中的控件、...
Android为我们提供了很多种AlertDialog,当前我们也可以定制自己需要的Dialog;
自定义右上角带叉号的Dialog ,自定义布局的dialog,支持点击事件
主要讲解了平常用的对话框Dialog AlertDialog 和弹出框PopupWindow
Google官方推荐使用DialogFragment代替AlertDialog,很好的解决屏幕旋转产生的问题。。。
我们添加的按钮不论是用setNegativeButton还是用setPositiveButton添加的按钮,点击的时候,都会关闭对话框,但是我们的一 些实际需求,就需要保留这个对话框不动,例如输入校验码,...而关闭后弹出对话框,就很别扭了
自己总结的,在Android中 Activity与 AlertDialog 值传递的例子 有一个EditText和两个EditText,将值返回给Activity中的 TextView
NULL 博文链接:https://676744379-qq-com.iteye.com/blog/1122485
在Android中实现Iphone样式的AlertDialog; 使用Dialog实现。