Android系统对话框

效果图

2个按钮的对话框

3个按钮的对话框

自定义View的对话框

单选对话框

多选对话框

列表框

Code

XML

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.kongqw.dialogdemo.MainActivity"> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="button1"
android:text="2个按钮的对话框" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="button2"
android:text="3个按钮的对话框" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="button3"
android:text="一个View" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="button4"
android:text="单选框" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="button5"
android:text="复选框" /> <Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="button6"
android:text="列表框" />
</LinearLayout>

主类

package com.kongqw.dialogdemo;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast; public class MainActivity extends AppCompatActivity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} public void button1(View view) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("确认退出吗?");
builder.setTitle("提示");
builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
finish();
}
});
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.create().show();
} public void button2(View view) {
Dialog dialog = new AlertDialog.Builder(this)
.setIcon(android.R.drawable.btn_star)
.setTitle("升级")
.setMessage("发现新版本")
.setPositiveButton("升级", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "升级", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("不升级", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "不升级", Toast.LENGTH_SHORT).show();
}
})
.setNeutralButton("忽略", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "忽略", Toast.LENGTH_SHORT).show();
}
})
.create();
dialog.show();
} public void button3(View view) {
new AlertDialog.Builder(this)
.setTitle("请输入")
.setIcon(android.R.drawable.ic_dialog_info)
// .setView(new EditText(this))
.setView(View.inflate(this, R.layout.bitmain_tab, null))
.setPositiveButton("确定", null)
.setNegativeButton("取消", null)
.show();
} public void button4(View view) {
new AlertDialog.Builder(this)
.setTitle("单选框")
.setIcon(android.R.drawable.ic_dialog_info)
.setSingleChoiceItems(new String[]{"Android", "IOS"}, 0, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
}).setNegativeButton("取消", null).show();
} public void button5(View view) {
new AlertDialog.Builder(this)
.setTitle("复选框")
.setMultiChoiceItems(new String[]{"Android", "IOS"}, null, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int which, boolean isChecked) {
Toast.makeText(MainActivity.this,"which = " + which + " isChecked = " + isChecked,Toast.LENGTH_SHORT).show();
}
})
.setPositiveButton("确定", null)
.setNegativeButton("取消", null)
.show();
} public void button6(View view) {
new AlertDialog.Builder(this)
.setTitle("列表框")
.setItems(new String[]{"Item1", "Item2"}, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this,"which = " + which,Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("确定", null)
.show();
}
}

自定义View

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"> <EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="请输入内容1"/> <EditText
android:id="@+id/editText2"
android:layout_margin="10dp"
android:layout_below="@id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="请输入内容2"/> </RelativeLayout>

Android系统对话框的更多相关文章

  1. Android系统对话框——自定义关闭

    Android系统对话框--自定义关闭 Dialog是我们在项目中经常用到的,5.x以后的Dialog也很好看,很安卓风,Android也给我们提供了新的包,低版本可以显示一样的效果.我们在使用的导入 ...

  2. Android———最详细的系统对话框使用

    在实际应用开发中,用到系统对话框中的情况几乎是没有的.按开发流程来说,UI工程师都会给出每一个弹窗的样式,故而在实际开发中都是自定义弹窗的. 即使用到的地方不多,但是我们也是需要了解并且能熟练的运用它 ...

  3. Android———最详细的系统对话框(AlertDialog)详解

    在实际应用开发中,用到系统对话框中的情况几乎是没有的.按开发流程来说,UI工程师都会给出每一个弹窗的样式,故而在实际开发中都是自定义弹窗的. 即使用到的地方不多,但是我们也是需要了解并且能熟练的运用它 ...

  4. 理解WebKit和Chromium: 调试Android系统上的Chromium

    转载请注明原文地址:http://blog.csdn.net/milado_nju 1. Android上的调试技术 在Android系统上,开发人员能够使用两种不同的语言来开发应用程序,一种是Jav ...

  5. 【Android 系统开发】 编译 Android文件系统 u-boot 内核 并烧写到 OK-6410A 开发板上

    博客地址 : http://blog.csdn.net/shulianghan/article/details/40299813  本篇文章中用到的工具源码下载 : -- ok-6410A 附带的 A ...

  6. Android系统的三种分屏显示模式

    Google在Android 7.0中引入了一个新特性——多窗口支持,允许用户一次在屏幕上打开两个应用.在手持设备上,两个应用可以在"分屏"模式中左右并排或上下并排显示.在电视设备 ...

  7. Android系统裁剪:手把手教你如何进行系统裁剪

    前言:android系统裁剪优化一直是各个厂商定制产品的关键步骤,包括浅层次的去除不必要的apk(android apk裁剪定制 )和深层次的裁剪整个编译系统和框架层.   android作为开源系统 ...

  8. Android自定义组件系列【13】——Android自定义对话框如此简单

    在我们的日常项目中很多地方会用到对话框,但是Android系统为我们提供的对话框样子和我们精心设计的界面很不协调,在这种情况下我们想很自由的定义对话框,或者有的时候我们的对话框是一个图片,没有标题和按 ...

  9. 线程、进程概念与Android系统组件的关系

    Android系统是Google公司基于Linux内核开发的开源手机操作系统.通过利用 Linux 内核的优势,Android 系统使用了大量操作系统服务,包括进程管理.内存管理.网络堆栈.驱动程序. ...

随机推荐

  1. 集合之ArrayList的源码分析

    转载请注明出处 一.介绍 对于ArrayList,可以说诸位绝不陌生,可以说是在诸多集合中运用的最多一个类之一,那么它是怎样构成,怎样实现的呢,相信很多人都知道数组构成的,没毛病,如果遇到面试的时候, ...

  2. 【转】Impala导出查询结果到文件

    [转载出处]http://blog.csdn.net/jobschen/article/details/68942574 想用impala-shell 命令行中将查询的结果导出到本地文件,想当然的以为 ...

  3. LeetCode题目----求中位数---标签:Array

    题目难度---困难 题目要求: 给定两个大小为 m 和 n 的有序数组 nums1 和 nums2 . 请找出这两个有序数组的中位数.要求算法的时间复杂度为 O(log (m+n)) . 思路:第一眼 ...

  4. [Codeforces 864C]Bus

    Description A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After ...

  5. poj 1367 robot(搜索)

    题意:给你一个图,求起点 到 终点的最少时间 每次有两种选择①:往前走1~3步                ②原地选择90°   费时皆是1s 图中1为障碍物,而且不能出边界.还要考虑机器人的直径 ...

  6. Codeforces Round#403 (Div. 1)

    唉,昨天晚上迷迷糊糊地去打cf,结果fst两题,掉回蓝了... A.Andryusha and Colored Balloons 题意:给定一棵树,任意两个距离小等于二的点不能染相同的颜色,求最小颜色 ...

  7. bzoj4011[HNOI2015]落忆枫音 dp+容斥(?)

    4011: [HNOI2015]落忆枫音 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 1125  Solved: 603[Submit][Statu ...

  8. 对I/O设备分配的一般策略是什么?

    策略是:独享分配.共享分配.虚拟分配 补充:I/O设备的分配算法 1.  先请求先服务 2.  优先级最高者优先

  9. cisco 的六种模式(cisco 系统)

  10. JS文件中获取contextPath的方法

    function getContextPath() {    var pathName = document.location.pathname;    var index = pathName.su ...