Android游戏开发系统控件-Dialog
Android游戏开发系统控件-Dialog
Dialog(对话框)在Android应用开发中经常用到,下面是学习《Android游戏编程从零开始》一书,关于Dialog的初步学习。
创建项目:DialogProject
作者:wwj
日期:2012/5/13
功能:显示有TextView和按钮的对话框
简单对话框:
添加单选框的对话框:
添加多选框的对话框:
添加列表的对话框:
添加自定义布局的对话框:
项目源代码:
=>>main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:orientation="vertical" ><TextViewandroid:layout_width="fill_parent"android:layout_height="wrap_content"android:text="@string/hello" /></LinearLayout>
=>>dialogmain.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_height="wrap_content"android:layout_width="wrap_content"android:background="#ffffffff" android:orientation="horizontal"android:id="@+id/myLayout"><TextViewandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="TextView"/><EditText android:layout_width="wrap_content"android:layout_height="wrap_content"/><Button android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="btn1"/><Buttonandroid:layout_width="wrap_content"android:layout_height="wrap_content"android:text="btn2"/>
</LinearLayout>
=>>DialogProjectActivity.java
package com.dialog;import android.app.Activity;
import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;public class DialogProjectActivity extends Activity {private Builder builder; //声明Bulider对象/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);//实例化Builder对象builder = new Builder(DialogProjectActivity.this);//设置对话框的图标builder.setIcon(android.R.drawable.ic_dialog_info);//设置对话框的标题builder.setTitle("Dialog");//设置对话框提示文本// builder.setMessage("Dialog对话框");//监听左侧按钮builder.setPositiveButton("Yes", new OnClickListener(){public void onClick(DialogInterface dialog,int which){}});//监听右侧按钮builder.setNegativeButton("No",new OnClickListener(){public void onClick(DialogInterface dialog,int which){}});/*//添加单选按钮builder.setSingleChoiceItems(new String[]{"单选","单选"},1,newOnClickListener(){public void onClick(DialogInterface dialog,int which){//which:选中下标}});//添加复选框builder.setMultiChoiceItems(new String[]{"多选","多选"},new boolean[]{false, true},new OnMultiChoiceClickListener(){public void onClick(DialogInterface dialog,int which,boolean isChecked){//which:选中下标//isChecked:选中项的勾选状态}});//添加列表项builder.setItems(new String[]{"列表项1","列表项2","列表项3"},new OnClickListener(){public void onClick(DialogInterface dialog,int which){//which:选中下标项}});*///实例layout布局LayoutInflater inflater = getLayoutInflater();View layout = inflater.inflate(R.layout.dialogmain, (ViewGroup)findViewById(R.id.myLayout));builder.setView(layout);//调用show()方法显示对话框builder.show();}
}
转载于:https://www.cnblogs.com/wwj9413/archive/2012/05/13/2638587.html
Android游戏开发系统控件-Dialog相关推荐
- Android游戏开发系统控件-CheckBox
Android游戏开发系统控件-CheckBox 2012/5/11 星期五 CheckBox是Android系统最普通的UI控件,继承了Button按钮 下面通过一个实例来学习 作者:wwj 功能: ...
- 【安卓开发 】Android初级开发(一)控件通用属性
控件通用属性 match_parent 是指和父容器宽高相等的值,其他的同理可证. android:layout_marginTop="XXXXXXdp" 距离顶部的距离 Andr ...
- 【ANDROID游戏开发之六】在SURFACEVIEW中添加系统控件,并且相互交互数据!
本站文章均为 李华明Himi 原创,转载务必在明显处注明: 转载自[黑米GameDev街区] 原文链接: http://www.himigame.com/android-game/306.html - ...
- Android UI 统一修改Button控件的样式,以及其它系统控件的默认样式
先介绍下修改原理:首先打开位于android.widget包下面的Button.java文件,这里有一句关键的代码如下: public Button(Context context, Attribut ...
- android layout 替换,LayoutInflater 后记--替换系统控件
之前记录了自己走通 LayoutInflater 的源码整体流程,一直想搞个好玩的东西,想起之前看到过的换肤方案,决定写个换系统控件的库. 项目地址,项目的具体使用,可以看README 首先需要确定, ...
- Android系统控件获取自定义属性
我们如果想在ImageView,Button,TextView等系统控件中在XML中配置自定义属性该如何实现呢?例如我们有一个scrollView,在ScrollView里面有上述的一些控件的自定义属 ...
- Android引用RN第三方控件,Android和RN互调方式,最近开发心得
"有人住高楼,有人在深沟,有人光万丈,有人一身锈,世人万千种,浮云莫去求,斯人若彩虹,遇上方知有." 时隔四季,我重新开始了我的文章更新,so do you miss me? 前言 ...
- Android游戏开发Android软件开发【教程三十篇】
Android软件开发之发送短信与系统短信库解析(三十) New Android软件开发之获取通讯录联系人信息(二十九) New Android软件开发之PreferenceActivity中的组 ...
- Android常用酷炫控件(开源项目)github地址汇总
转载一个很牛逼的控件收集帖... 第一部分 个性化控件(View) 主要介绍那些不错个性化的 View,包括 ListView.ActionBar.Menu.ViewPager.Gallery.Gri ...
最新文章
- 华为H3C ER3100由器限速方法合集
- Lock锁的基本使用
- crontab shell 每5秒执行_centos 定时任务按秒执行crontab
- 闭包引起的onclick不起作用
- 插件化框架DL源码的简单解析
- Vue.js过滤器概述
- Android JNI开发系列(二)HelloWorld
- 机器学习:监督学习和无监督学习
- 移植SlidingMenu Android library,和安装example出现的问题解决
- java并发包是谁编写的_0.Java并发包系列开篇
- 软件研发的绩效考核漫谈一
- Linux对文本查找、检索、统计及替换的常用命令
- 阿里云Centos7修改22默认端口
- matlab测量正六边形边长,计算边长已知的正六边形面积的方法
- mysql部分常用函数DATE_FORMAT(a.Created_time,'%Y-%m-%d%H
- 寒冰王座(完全背包)
- 【网络设备配置与管理实验二】路由器口令的配置
- springboot实现长链接转短链接
- “英语”有多少个字母?
- 笔记本电脑死机重启故障
热门文章
- 前端学习(3294):effect hook
- 前端学习(3221):类式组件中的props
- [html] 如果让你实现一个网页版的办公表格(类似excel),你觉得是否可行?如果可行应该怎么做?
- [vue] vue怎么改变插入模板的分隔符?
- [css] 如何隐藏没有静音、自动播放的音视频?
- 前端学习(2561):页面更新
- 前端学习(2007)vue之电商管理系统电商系统之优化复选框的样式
- 前端学习(1675):前端系列实战课程之无缝滚动思路
- 前端学习(869):高级事件导读
- mybatis学习(5):安装 SQL Server installsharewowdir命令值无效的问题