• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > Android中Dialog对话框,androiddialog

Android中Dialog对话框,androiddialog

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了android dialog对话框,android dialog输入框,android dialog,android中dialog,android 自定义dialog等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Android中Dialog对话框,androiddialog


布局文件xml:

复制代码
 1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 2     xmlns:tools="http://schemas.android.com/tools"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context=".DialogActivity" >
11 
12     <Button
13         android:id="@+id/plainDialog"
14         android:layout_width="match_parent"
15         android:layout_height="wrap_content"
16         android:text="普通Dialog" />
17 
18     <Button
19         android:id="@+id/plainDialogEvent"
20         android:layout_width="match_parent"
21         android:layout_height="wrap_content"
22         android:text="Dialog按钮事件集中处理" />
23 
24     <Button
25         android:id="@+id/inputDialog"
26         android:layout_width="match_parent"
27         android:layout_height="wrap_content"
28         android:text="请输入框" />
29 
30     <Button
31         android:id="@+id/listDialog"
32         android:layout_width="match_parent"
33         android:layout_height="wrap_content"
34         android:text="列表对话框" />
35 
36     <Button
37         android:id="@+id/radioDialog"
38         android:layout_width="match_parent"
39         android:layout_height="wrap_content"
40         android:text="单选对话框" />
41 
42     <Button
43         android:id="@+id/checkboxDialog"
44         android:layout_width="match_parent"
45         android:layout_height="wrap_content"
46         android:text="多选对话框" />
47 
48     <Button
49         android:id="@+id/diyDialog"
50         android:layout_width="match_parent"
51         android:layout_height="wrap_content"
52         android:text="自定义布局对话框" />
53 
54 </LinearLayout>
复制代码

Activity文件:

普通的dialog:

复制代码
 1 private void plainDialogDemo() {
 2 
 3         Button plainBtn = (Button) findViewById(R.id.plainDialog);
 4         plainBtn.setOnClickListener(new OnClickListener() {
 5 
 6             public void onClick(View v) {
 7 
 8                 new AlertDialog.Builder(DialogActivity.this)
 9                         .setTitle("删除")
10                         .setMessage("确定删除指定数据")
11                         .setPositiveButton("确定",
12                                 new DialogInterface.OnClickListener() {
13 
14                                     @Override
15                                     public void onClick(DialogInterface dialog,
16                                             int which) {
17                                         Toast.makeText(getApplicationContext(),
18                                                 "确定了", Toast.LENGTH_SHORT)
19                                                 .show();
20                                     }
21                                 })
22                         .setNegativeButton("取消",
23                                 new DialogInterface.OnClickListener() {
24 
25                                     @Override
26                                     public void onClick(DialogInterface dialog,
27                                             int which) {
28                                     }
29                                 }).setCancelable(false).show();
30             }
31         });
32     }
复制代码

效果如下:

输入文本框的dialog:

复制代码
 1 private void inputDialog() {
 2         Button inputBtn = (Button) findViewById(R.id.inputDialog);
 3         inputBtn.setOnClickListener(new OnClickListener() {
 4 
 5             @Override
 6             public void onClick(View v) {
 7                 // TODO Auto-generated method stub
 8                 final EditText et = new EditText(DialogActivity.this);
 9                 new AlertDialog.Builder(DialogActivity.this)
10                         .setTitle("请输入数字")
11                         .setView(et)
12                         .setPositiveButton("确定",
13                                 new DialogInterface.OnClickListener() {
14 
15                                     @Override
16                                     public void onClick(DialogInterface dialog,
17                                             int which) {
18                                         // TODO Auto-generated method stub
19                                         Toast.makeText(getApplicationContext(),
20                                                 et.getText(),
21                                                 Toast.LENGTH_SHORT).show();
22                                     }
23                                 }).setNegativeButton("取消", null)
24                         .setCancelable(false).show();
25             }
26         });
27     }
复制代码

效果如下:

列表dialog:

复制代码
private void listDialogDemo() {
        Button listBtn = (Button) findViewById(R.id.listDialog);
        listBtn.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                final String[] names = { "C罗", "J罗", "H罗" };
                new AlertDialog.Builder(DialogActivity.this).setTitle("列表对话框")
                        .setItems(names, new DialogInterface.OnClickListener() {

                            @Override
                            public void onClick(DialogInterface dialog,
                                    int which) {
                                Toast.makeText(DialogActivity.this,
                                        names[which], Toast.LENGTH_SHORT)
                                        .show();
                            }
                        }).setNegativeButton("取消", null).show();
            }
        });
    }
复制代码

效果如下:

单选dialog:

复制代码
 1 private void radioDialogDemo() {
 2         Button radioButton = (Button) findViewById(R.id.radioDialog);
 3         radioButton.setOnClickListener(new OnClickListener() {
 4 
 5             @Override
 6             public void onClick(View v) {
 7 
 8                 final String[] names = { "C罗", "J罗", "H罗" };
 9                 new AlertDialog.Builder(DialogActivity.this)
10                         .setTitle("列表对话框")
11                         .setSingleChoiceItems(names, 0,
12                                 new DialogInterface.OnClickListener() {
13 
14                                     @Override
15                                     public void onClick(DialogInterface dialog,
16                                  



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Android中Dialog对话框,androiddialog

相关文章

  • 2017-05-26【RecyclerView与Glide】实现一个Android电子书阅读APP,gliderecyclerview
  • 2017-05-26牛刀小试Oracle之ORACLE 11GR2 RAC安装配置--先决配置阶段
  • 2017-05-26Android Studio中的EditText控件使用详解
  • 2017-08-23Android实现支付宝支付
  • 2017-05-26android——从零开始,android从零开始
  • 2017-05-26通过redhat crash utility从ramdump中获取ftrace log
  • 2017-05-26Android SwipeRefreshLayout下拉刷新与上拉加载+滑动删除
  • 2017-05-26活动的生命周期(三):实例上机课,生命周期上机
  • 2017-05-26[android] 手机卫士设备管理权限锁屏,android锁屏
  • 2017-05-26违章查询源码分享,违章查询源码

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 硅谷社交6--添加联系人--发送添加好友邀请,硅谷6--
    • Android四种常见设计模式说明
    • 如何判断设备是平板还是手机,判断设备平板手机
    • node.js 通过ajax上传图片
    • android开发时间和日期的代码实现工具类(一),android工具类
    • Android 友盟分享详细集成过程及所遇问题解决,android
    • 2.6.2 菜单(Menu)
    • android studio 中去除应用标题栏,androidstudio
    • Intent(三)向下一个活动传递数据,intent传递
    • Android新手入门2016(11)--非阻塞对话框AlertDialog

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有