菜鸟Android学习之路30——是否退出对话框
来源:互联网 发布:网络stp 编辑:程序博客网 时间:2024/06/06 03:14
xml文件代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<ImageButton
android:contentDescription="@string/background"
android:id="@+id/imageButton1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/picw01"
/>
</LinearLayout>
maia_activity代码:
ImageButton button1 = (ImageButton)findViewById(R.id.imageButton1);
button1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
AlertDialog alert = new AlertDialog.Builder(MainActivity.this).create();
// 设置图标
alert.setIcon(R.drawable.img06);
// 设置标题
alert.setTitle("是否退出?");
// 设置内容
alert.setMessage("真的不看这美女的身体了?");
// 添加取消按钮
alert.setButton(DialogInterface.BUTTON_NEGATIVE, "no", new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
// 添加确定按钮
alert.setButton(DialogInterface.BUTTON_POSITIVE, "YES",new OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
finish();
}
});
alert.show();
}
});
效果如下:
- 菜鸟Android学习之路30——是否退出对话框
- 菜鸟Android学习之路26——消息提示框和对话框
- 菜鸟Android学习之路28——AlertDialog(1)带取消、确认按钮对话框
- 菜鸟Android学习之路28——AlertDialog(2)带列表的列表对话框
- 菜鸟Android学习之路28——AlertDialog(4)显示带多个选列表项的对话框
- android 返回弹出是否退出对话框
- android菜鸟飞翔之路——SurfaceView学习
- 菜鸟Android学习之路03——线性布局
- 菜鸟Android学习之路04——基本组件
- 菜鸟Android学习之路06——图像视图
- 菜鸟Android学习之路09——列表视图
- 菜鸟Android学习之路13——图片按钮
- 菜鸟Android学习之路22——网格视图
- 菜鸟Android学习之路27——notification
- 菜鸟Android学习之路29——AlertDialog
- Android菜鸟学习之路——AndroidStudio快捷键
- Android菜鸟学习之路——Activity生命周期
- android菜鸟学习之路
- .数据库、表的建立,记录的添加、查询、修改和删除
- linux tips
- java中的abstract
- 变量的定义与声明(转载自周公)
- hive函数 -- asin
- 菜鸟Android学习之路30——是否退出对话框
- 有道云笔记同步IT笔试面试资源
- Python
- 芋头
- Oracle复制表结构
- windows命令行重定向输出到NULL
- Eclipse快捷键使用总结
- android 自定义ImageView实现图片手势滑动,多点触摸放大缩小效果
- 设置设备进行开发