- 浏览: 547806 次
- 性别:
- 来自: 武汉
文章分类
最新评论
-
北月与南安:
哥哥不要秀我,答案是11.38,你算出来36.43,要求N个点 ...
平均距离 -
xiao_android_jun:
[color=red][ size=xx-small ...
Android 之 进程的概念介绍 -
明子健:
小伙子,很有前途哦
《将博客搬至CSDN》 -
1140566087:
dugujiujian 写道R.layout.simple_s ...
Android 之 下拉(Spinner) 组件示例 -
dugujiujian:
R.layout.simple_spinner_dropdow ...
Android 之 下拉(Spinner) 组件示例
各种对话测试布局文件:
主程序代码测试:
=============================自定义对话框======================================
自定义对话框布局文件
主程序入口:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <Button android:id="@+id/user_dialog" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="自定义对话框测试" /> <Button android:id="@+id/general_list_dialog" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="普通列表对话框测试" /> <Button android:id="@+id/multic_list_dialog" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="多选列表对话框测试" /> <Button android:id="@+id/radio_list_dialog" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="单选列表对话框测试" /> <Button android:id="@+id/adapter_list_dialog" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="提供列表项的列表对话框测试" /> </LinearLayout>
主程序代码测试:
/* * 对话框测试主入口 * @author Administrator * */ public class DialogMainActivity extends Activity { private RadioGroup color,size; private RadioButton c1,c2,c3,c4,c5,s1,s2,s3,s4,s5; private TextView textView; private Button general,multic,radio,adapter,user; // 初始化 public void init(){ user = (Button) findViewById(R.id.user_dialog); general = (Button) findViewById(R.id.general_list_dialog); multic = (Button) findViewById(R.id.multic_list_dialog); radio = (Button) findViewById(R.id.radio_list_dialog); adapter = (Button) findViewById(R.id.adapter_list_dialog); } // 程序入口 protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.dialog_main_layout); init(); // 初始化 user.setOnClickListener(listener); general.setOnClickListener(listener); multic.setOnClickListener(listener); radio.setOnClickListener(listener); adapter.setOnClickListener(listener); } /** * 普通列表对话框测试 */ public void generalListDialog(){ Builder b = new Builder(this); b.setTitle("普通列表对话框测试"); b.setIcon(R.drawable.ic_launcher); b.setItems(new String[]{"西方","南方","北方","西北方"},new OnClickListener() { public void onClick(DialogInterface dialog, int which) { // which 代表被点击的项 Toast.makeText(DialogMainActivity.this, "选中了:"+new String[]{"西方","南方","北方","西北方"}[which],Toast.LENGTH_LONG).show(); } }); b.create(); b.show(); } /** * 单选对话框测试 */ public void radioListDialog(){ Builder b = new AlertDialog.Builder(this); b.setTitle("单选列表对话框测试"); b.setIcon(R.drawable.ic_launcher); final String[] data = new String[]{"男","女","中"}; /* * 参数: 数据 默认选项 事件 */ b.setSingleChoiceItems(data, 0, new OnClickListener() { public void onClick(DialogInterface dialog, int which) { Toast.makeText(DialogMainActivity.this, "选中了:"+data[which],Toast.LENGTH_LONG).show(); } }); // 确定 b.setPositiveButton("确定", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); // 取消 b.setNegativeButton("取消",new OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); b.create(); b.show(); } /** * 创建多选列表对话框 */ public void multicListDialog(){ Builder b = new AlertDialog.Builder(this); b.setTitle("多选列表对话框测试"); b.setIcon(R.drawable.ic_launcher); final String[] data = new String[]{"吃饭","冲浪","散步"}; /* * 参数: 数据 默认选项 事件 */ b.setMultiChoiceItems(data, null, new OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int which, boolean isChecked) { /* which 索引 - isChecked 是否被选中 */ if(isChecked){ Toast.makeText(DialogMainActivity.this, "选中了:"+data[which],Toast.LENGTH_LONG).show(); } } }); // 确定 b.setPositiveButton("确定", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); // 取消 b.setNegativeButton("取消",new OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); b.create(); b.show(); } /** * 提供列表项的对话框测试 */ public void adapterListDialog(){ Builder b = new AlertDialog.Builder(this); b.setTitle("提供列表对话框测试"); // 标题 b.setIcon(R.drawable.ic_launcher); // 图标 /* * 参数: 数据 默认选项 事件 */ // 确定 b.setPositiveButton("确定", new OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); // 取消 b.setNegativeButton("取消",new OnClickListener() { public void onClick(DialogInterface dialog, int which) { } }); b.create(); b.show(); } // 事件 -- 测试各种动作 private android.view.View.OnClickListener listener = new View.OnClickListener() { public void onClick(View v) { if(v.getId() == R.id.general_list_dialog){ // 普通测试 generalListDialog(); return; } if(v.getId() == R.id.user_dialog){ // 自定义测试 userDialog(); return; } if(v.getId() == R.id.radio_list_dialog){ // 单选测试 radioListDialog(); return; } if(v.getId() == R.id.multic_list_dialog){ // 多选测试 multicListDialog(); return; } if(v.getId() == R.id.adapter_list_dialog){ // 多选测试 adapterListDialog(); return; } } }; /** * 自定义对话框测试 */ public void userDialog(){ // 创建对话框对象 Builder builder = new Builder(this); builder.setTitle("字体样式选择"); // 设置标题 builder.setIcon(R.drawable.ic_launcher); // 设置图标 // 确定按钮 -- 执行预期动作 builder.setPositiveButton("确定",new OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); /* 载入自定义布局文件 -- 达成自定义的效果 */ LayoutInflater inflater = LayoutInflater.from(this); // 获取视图容器对象 // 根据视图容器获取布局对象 LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.user_dialog_item,null); builder.setView(layout); // 将布局视图显示在对话框中 // 获取自定义布局中的组件对象 color = (RadioGroup) layout.findViewById(R.id.colorRadioGroup); size = (RadioGroup) layout.findViewById(R.id.sizeRadioGroup); c1 = (RadioButton) layout.findViewById(R.id.c1); c2 = (RadioButton) layout.findViewById(R.id.c2); c3 = (RadioButton) layout.findViewById(R.id.c3); c4 = (RadioButton) layout.findViewById(R.id.c4); s1 = (RadioButton) layout.findViewById(R.id.s1); s2 = (RadioButton) layout.findViewById(R.id.s2); s3 = (RadioButton) layout.findViewById(R.id.s3); s4 = (RadioButton) layout.findViewById(R.id.s4); // 设置监听器 color.setOnCheckedChangeListener(radioListener); size.setOnCheckedChangeListener(radioListener); /* ------------------------------------------------------------------ */ // 取消按钮,点击取消对话框 builder.setNegativeButton("取消",new OnClickListener() { public void onClick(DialogInterface dialog, int which) { // TODO Auto-generated method stub } }); builder.create(); // 创建 builder.show(); // 显示 } // RadioGroup 事件改变监听器 private OnCheckedChangeListener radioListener = new OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { if(checkedId == c1.getId()){ // Toast.makeText(DialogMainActivity.this,"字体颜色", 1000).show(); } if(checkedId == s1.getId()){ Toast.makeText(DialogMainActivity.this,"字体大小", 1000).show(); } } }; }
=============================自定义对话框======================================
自定义对话框布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/user_layout" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:orientation="vertical" android:padding="15dp" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center_horizontal" android:text="请看这里" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="颜色选择:" /> <RadioGroup android:id="@+id/colorRadioGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/c1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RadioButton android:id="@+id/c2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RadioButton android:id="@+id/c3" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RadioButton android:id="@+id/c4" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RadioGroup> </LinearLayout> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:orientation="horizontal" > <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="颜色选择:" /> <RadioGroup android:id="@+id/sizeRadioGroup" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" > <RadioButton android:id="@+id/s1" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RadioButton android:id="@+id/s2" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RadioButton android:id="@+id/s3" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <RadioButton android:id="@+id/s4" android:layout_width="wrap_content" android:layout_height="wrap_content" /> </RadioGroup> </LinearLayout> </LinearLayout>
主程序入口:
- dialog.rar (1.2 MB)
- 下载次数: 8
发表评论
-
Android 之 网络访问服务器,解析JSON数据
2014-03-28 22:50 3343提示:在访问网络,或者服务器的数据一定要注意 网络权限的声明: ... -
Android 之 AsyncTask 异步任务
2014-03-20 08:44 3482Android ... -
Android 之 Looper Handler Message 之间的关系
2014-03-19 10:16 3615Android 的消息 ... -
Android 之 多线程与Socket联合使用案例
2014-03-19 10:15 2607多线 ... -
Android 之 多线程和Socket套接字的使用介绍
2014-03-19 10:15 4820And ... -
Android 之 实现Runnable 接口与继承Thread的区别
2014-03-19 10:15 2155实现Runnable 接口 相 ... -
Android 之 GSON解析JSON数据
2014-03-19 10:14 4427... -
Android 之 使用Pull 解析xml文件
2014-03-18 21:04 1003/** * 使用Pull进行 xml 文件的解析 ... -
Android 之 使用DOM解析xml文件
2014-03-18 21:02 2695DOM 解析 xml 格式的文件 1、 xml简介:xml ... -
Android 之 百度API 密钥安全码生成
2014-03-04 22:29 2333近期要做个关于旅游助手的应用,开始接触百度API了。大神们 ... -
Android 之 EditText属性用法介绍
2014-01-06 23:49 3947EditText的属性 EditText继承关系:View-- ... -
Android 之 自定义适配器
2014-01-08 10:40 1706自定义适配器 1、实现 * 自定义适配器要继承 BaseA ... -
Android 之 自定义控件用法介绍
2014-01-08 10:40 1682自定义效果:实现:图片和文字混合 首先创建需要组合的子布局: ... -
Android 之 资源自适应与国际化
2014-01-08 10:40 3019<!-- 国际化和资源自适应 ... -
Android 之 Parcelable 序列化
2014-01-08 10:41 2653/* 序列化 * * 作 ... -
Android 之 五大布局案例
2014-01-08 10:41 20981、LinearLayout 线性布局例子: <Lin ... -
Android 之 通知Notification
2014-03-03 22:30 3825Notification 和 NotificationMana ... -
Android 之 手机全屏显示
2014-03-03 22:30 2285/* 1、全屏状态的显示 介绍:Android 中提供了Wi ... -
Android 之 拦截手机短信并自动转发
2014-03-03 22:29 5436拦截短信和发送短信都需要相关的权限: <?xml ve ... -
Android 之 将RAW资源文件写入SD卡工具类
2014-03-01 10:09 3514package com.sun.coptfiletosd; ...
相关推荐
android对话框总结
Android对话框的总结(8.15)
简单的总结:自定义对话框有如下步骤。 1.自定义对话框样式(R.style.xxx) 2.自定义对话框布局(R.layout.xxx) 3.通过Dialog构建对话框(Dialog.setContentView(R.layout.xxx)) 4.处理事件和业务逻辑(按钮,列表,...
这个代码对应Android基础篇-对话框总结(普通对话框,单选框,多选框,自定义对话框)这篇博客上所有代码,免费下载,以调试可以正常运行。
本人总结了常用Android对话框(dialog)案列,借鉴网上的资源,总结出日常所用的经典对话框。适合日常开发借鉴使用,也适合初学者学习。
一:AlterDialog对话框 2:对话框圆角显示(在drawable下创建radius_bomb_box.xml) 3:Styles样式设置 @color/colorPrimary @color/colorPrimaryDark ... @android:color/transparent true @null
本文档总结了android中的对话框的使用以及源代码!希望可以广大的android学习者带来一定的帮助
本人总结了常用Android对话框(dialog)案列,借鉴网上的资源,总结出日常所用的经典对话框。适合日常开发借鉴使用,也适合初学者学习。||前期下载过Android对话框精粹1的朋友们,本次是对上次的更新,里面增加了很...
android对话框使用很广泛,看了很多,总结了一下
android dialog总结Dialog整理.rar,太多无法一一验证是否可用,程序如果跑不起来需要自调,部分代码功能进行参考学习。
这里总结了九种对话框的实现方法,有需要的朋友可以来学习下了 除了popupwindow实现稍微麻烦一点,其他形似都相对简单,熟悉2便即可 直接上源码 package com.naoh.stu; import java.util.A
主要给大家总结了一些关于Android中Dialog对话框的使用方法,这其中包括普通对话框、确定取消对话框、多按钮对话框、列表对话框、带Adapter的对话框、单选对话框以及多选对话框等,需要的朋友可以参考学习,下面来...
activity变身对话框 onMeasure 中的AT_MOST EXACTLY UNSPECIFIED MotionEvent的触发记录 对于Drawable 的 getIntrinsicHeight 和getIntrinsicWidth的理解 IntentService 使用总结: 文件读写总结: AES 解密失败: ...
第2章 对话框 11 第3章 硬件菜单 17 第4章 输入选择组件 19 第5章 图片和按钮 30 第6章 日期和时间控件 34 第7章 进度条和滑动条 37 第8章 GridView和Gallery控件 43 第9章 AutoCompleteTextView提示输入建议 48 第...
如对话框背景等,或去google code找些开源的代码下来研究,学习人家的设计思想、模块功能的划分、代码组织结构等知识 这个过程中,涉及到的知识比较多,如版本管理工具SVN、Git、Mercurial,如设计模式Android实训...
最无私的Android资料(书籍+代码)分享[总结] Android中文帮助教程(非常合适新手入门) android程序编写及调试新手入门 大家一起学Android(Windows篇) android入门与提高必看指南 Android入门逆引手册 Android...
自己这里总结一下,有需要开发者可以按照如下步骤直接使用即可。 1.效果图如下 点击选择照相后,弹出如下选择对话框: 2. Dialog实现 布局 <LinearLayout xmlns:android=...
采用案例驱动模式展开讲解知识点,即介绍案例->案例涉及技术->展开知识点->总结的方式 本书作者从事多年一线开发和培训,讲解知识点力求细致,深入浅出 目 录 前言 第1章 Android操作系统概述 1 1.1 Android...