dialoginterfacedialog.dismiss()和dialog.cancel()有什么区别分别用在什么场合

dialoginterface  时间:2021-06-03  阅读:()

alertDialog对话框的DialogInterface dialo参数有什么用

当你要通过确定或取消按钮来关闭对话框的时候,你就可以通过这个dialog对象(实际上就是设置监听事件的这个dialog)来对自身进行dismiss,后面那个int类型参数你查一下api就知道了

android中带图标的按钮(ImageButton)怎么用

除了Android系统自带的Button按钮以外,还提供了带图标的按钮ImageButton 要制作带图标的按钮,首先要在布局文件中定义ImageButton,然后通过setImageDrawable方法来设置要显示的图标。

注意: 我们可以在布局文件中就直接设置按钮的图标,如 android:src=”@drawable/icon1″ 我们也可以在程序中设置自定义图标 imgbtn3.setImageDrawable(getResources().getDrawable(R.drawable.icon2)); 我们还可以使用系统自带的图标 imgbtn4.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_ing)); 设置完按钮的图标后,需要为按钮设置监听setOnClickListener,以此捕获事件并处理 下面的例子讲述的是由4个图标按钮组成的布局,其中三个按钮的图标是自定义的,第四个按钮的图标是系统的,当点击按钮1的时候,弹出dialog,当点击按钮2的时候,点击确定后,可以将按钮2的图标变成按钮3的图标,当点击按钮3的时候,按钮3的图标变成了系统打电话的图标,点击按钮4,显示一个提示dialog ImageButtonTest.java源代码 .loulijun.imagebutton; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; import android.content.DialogInterface; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.ImageButton; import android.widget.TextView; public class ImageButtonTest extends Activity { /** Called when the activity is first created. */ TextView iew; ImageButton imgbtn1; ImageButton imgbtn2; ImageButton imgbtn3; ImageButton imgbtn4; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); iew=(TextView)findViewById(iew); //分别取得4个ImageButton对象 imgbtn1=(ImageButton)findViewById(R.id.imagebutton1); imgbtn2=(ImageButton)findViewById(R.id.imagebutton2); imgbtn3=(ImageButton)findViewById(R.id.imagebutton3); imgbtn4=(ImageButton)findViewById(R.id.imagebutton4); //分别为ImageButton设置图标 //imgbtn1已经在main.xml布局中设置了图标,所以就不在这里设置了(设置图标即可在程序中设置,也可在布局文件中设置) imgbtn2.setImageDrawable(getResources().getDrawable(R.drawable.icon));//在程序中设置图标 imgbtn3.setImageDrawable(getResources().getDrawable(R.drawable.icon2)); imgbtn4.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_call_ing));//设置系统图标 //下面为各个按钮设置事件监听 imgbtn1.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Dialog dialog=new AlertDialog.Builder(ImageButtonTest.this) .setTitle("提示") .setMessage("我是ImageButton1") .setPositiveButton("确定",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub //相应的处理操作 } }).create(); dialog.show(); } }); imgbtn2.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Dialog dialog=new AlertDialog.Builder(ImageButtonTest.this) .setTitle("提示") .setMessage("我是ImageButton2,我要使用ImageButton3的图标") .setPositiveButton("确定",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub imgbtn2.setImageDrawable(getResources().getDrawable(R.drawable.icon2)); } }).create(); dialog.show(); } }); imgbtn3.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Dialog dialog=new AlertDialog.Builder(ImageButtonTest.this) .setTitle("提示") .setMessage("我是ImageButton3,我想使用系统打电话的图标") .setPositiveButton("确定",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub imgbtn3.setImageDrawable(getResources().getDrawable(android.R.drawable.sym_action_call)); } }).create(); dialog.show(); } }); imgbtn4.setOnClickListener(new Button.OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub Dialog dialog=new AlertDialog.Builder(ImageButtonTest.this) .setTitle("提示") .setMessage("我是使用的系统图标") .setPositiveButton("确定",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub //相应的处理操作 } }).create(); dialog.show(); } }); } } 布局文件main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/iew" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="ImageButton测试案例" /> <ImageButton android:id="@+id/imagebutton1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/icon1" /> <ImageButton android:id="@+id/imagebutton2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageButton android:id="@+id/imagebutton3" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <ImageButton android:id="@+id/imagebutton4" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </LinearLayout>

如何设置对话框的宽度和高度

AlertDialog.Builderdialog=newAlertDialog.Builder(this).setTitle(<br>"title").setIcon(android.R.drawable.ic_dialog_alert).setMessage(<br>"message").setPositiveButton("yes",newOnClickListener(){<br>publicvoidonClick(DialogInterfacearg0,intarg1){<br><br>}<br>}).setNegativeButton("no",<br>newOnClickListener(){<br>publicvoidonClick(DialogInterfacearg0,intarg1){<br>}<br>}).setCancelable(false);<br><br>/*方法1:<br>*将对话框的大小按屏幕大小的百分比设置<br>*/<br>WindowManagerm=getWindowManager();<br>Displayd=m.getDefaultDisplay();//获取屏幕宽、高用<br>WindowManager.LayoutParamsp=getWindow().getAttributes();//获取对话框当前的参数值<br>p.height=(int)(d.getHeight()*0.5);//高度设置为屏幕的0.5<br>p.width=(int)(d.getWidth()*0.8);//宽度设置为屏幕的0.8<br>dialog.show().getWindow().setAttributes(p);<br><br>/*方法2:<br>*获取对话框的窗口对象及参数对象以修改对话框的布局设置,<br>*可以直接调用getWindow(),表示获得这个Activity的Window<br>*对象,这样这可以以同样的方式改变这个Activity的属性.<br>*/<br>WindowdialogWindow=dialog.show().getWindow();<br>WindowManager.LayoutParamslp=dialogWindow.getAttributes();<br>dialogWindow.setGravity(CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);<br><br>/*<br>*lp.x与lp.y表示相对于原始位置的偏移.<br>*当参数值包含Gravity.LEFT时,对话框出现在左边,所以lp.x就表示相对左边的偏移,负值忽略.<br>*当参数值包含Gravity.RIGHT时,对话框出现在右边,所以lp.x就表示相对右边的偏移,负值忽略.<br>*当参数值包含Gravity.TOP时,对话框出现在上边,所以lp.y就表示相对上边的偏移,负值忽略.<br>*当参数值包含Gravity.BOTTOM时,对话框出现在下边,所以lp.y就表示相对下边的偏移,负值忽略.<br>*当参数值包含Gravity.CENTER_HORIZONTAL时<br>*,对话框水平居中,所以lp.x就表示在水平居中的位置移动lp.x像素,正值向右移动,负值向左移动.<br>*当参数值包含Gravity.CENTER_VERTICAL时<br>*,对话框垂直居中,所以lp.y就表示在垂直居中的位置移动lp.y像素,正值向右移动,负值向左移动.<br>*gravity的默认值为Gravity.CENTER,即Gravity.CENTER_HORIZONTAL|<br>*Gravity.CENTER_VERTICAL.<br>*<br>*本来setGravity的参数值为Gravity.LEFT|Gravity.TOP时对话框应出现在程序的左上角,但在<br>*我手机上测试时发现距左边与上边都有一小段距离,而且垂直坐标把程序标题栏也计算在内了,<br>*Gravity.LEFT,Gravity.TOP,Gravity.BOTTOM与Gravity.RIGHT都是如此,据边界有一小段距离<br>*/<br>lp.x=100;//新位置X坐标<br>lp.y=100;//新位置Y坐标<br>lp.width=300;//宽度<br>lp.height=300;//高度<br>lp.alpha=0.7f;//透明度<br><br>//当Window的Attributes改变时系统会调用此函数,可以直接调用以应用上面对窗口参数的更改,也可以用setAttributes<br>//dialog.onWindowAttributesChanged(lp);<br>dialogWindow.setAttributes(lp);

Android中添加事件监听器的方法有哪些?

很简单: myButton1.setOnClickListener(newButton.OnClickListener(){? ????????@Override? ????????public?voidonClick(View?v)?{? ????????}???????????? });

android 开发 怎么给dialog 中添加动画

AlertDialog控件类是可以添加按钮,标题等 如: AlertDialog ale = new AlertDialog.Builder(MainActivity.this).create(); ale.setTitle("操作提示"); ale.setMessage("绑定设备完成"); ale.setButton(DialogInterface.BUTTON_POSITIVE, "确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); ale.show();

dialog.dismiss()和dialog.cancel()有什么区别分别用在什么场合

他们两个都基本上一样的,public void cancel ()Cancel the dialog. This is essentially the same as calling dismiss(), but it will also call your DialogInterface.OnCancelListener (if registered). 这个是解释,dismiss()方法是线程安全的。

触摸云 26元/月 ,美国200G高防云服务器

触摸云触摸云(cmzi.com),国人商家,有IDC/ISP正规资质,主营香港线路VPS、物理机等产品。本次为大家带上的是美国高防2区的套餐。去程普通线路,回程cn2 gia,均衡防御速度与防御,防御值为200G,无视UDP攻击,可选择性是否开启CC防御策略,超过峰值黑洞1-2小时。最低套餐20M起,多数套餐为50M,适合有防御型建站需求使用。美国高防2区 弹性云[大宽带]· 配置:1-16核· ...

UCloud 618活动:香港云服务器月付13元起;最高可购3年,AMD/Intel系列

ucloud6.18推出全球大促活动,针对新老用户(个人/企业)提供云服务器促销产品,其中最低配快杰云服务器月付5元起,中国香港快杰型云服务器月付13元起,最高可购3年,有AMD/Intel系列。当然这都是针对新用户的优惠。注意,UCloud全球有31个数据中心,29条专线,覆盖五大洲,基本上你想要的都能找到。注意:以上ucloud 618优惠都是新用户专享,老用户就随便看看!点击进入:uclou...

2021年全新Vultr VPS主机开通云服务器和选择机房教程(附IP不通问题)

昨天有分享到"2021年Vultr新用户福利注册账户赠送50美元"文章,居然还有网友曾经没有注册过他家的账户,薅过他们家的羊毛。通过一阵折腾居然能注册到账户,但是对于如何开通云服务器稍微有点不对劲,对于新人来说确实有点疑惑。因为Vultr采用的是预付费充值方式,会在每月的一号扣费,当然我们账户需要存留余额或者我们采用自动扣费支付模式。把笔记中以前的文章推送给网友查看,他居然告诉我界面不同,看的不对...

dialoginterface为你推荐
自动识别查询快递单号查看单号怎么知道是那个快递公司的华为总裁女儿为啥姓孟孟晚舟是谁vga接口定义主板VGA接口两排针脚的循序是怎么排列自定义表情手机QQ自定义表情怎么添加模式识别算法模式识别的简史jstz举手望,草上马跑,打什么数字?天翼校园宽带电信校园宽带手机怎么上网微粒群算法多目标粒子群算法源程序什么是网络地址什么是IP地址?免费下载空间怎么下载免费的空间播放器
vps教程 cve-2014-6271 国外php主机 万网优惠券 太原联通测速平台 空间论坛 太原网通测速平台 最漂亮的qq空间 linode支付宝 秒杀品 游戏服务器出租 windowsserver2008r2 海外加速 优惠服务器 服务器是什么意思 so域名 linuxvi 神棍节 paypal兑换 tracert 更多