Android 各种Dialog整理
来源:互联网 发布:重生之网络大亨txt下载 编辑:程序博客网 时间:2024/06/05 11:26
============================效果图==========================
效果图(1)
效果图(2)
效果图(3)
效果图(4)
效果图(5)
================================Scr code===============================
package com.ygc.dialog.activity;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
*
* <p>Title: Dialog_DemoActivity.java</p>
* <p>Description: 各种对话框示例</p>
* <p>Copyright: Copyright (c) 2011</p>
* <p>Company: Xawx Teachnology</p>
* <p>CreateTime: 2012-9-14 下午2:05:54</p>
*
* @author ygc
* @version %A%, %B%
* @since JDK1.6
* @CheckItem null
*/
public class Dialog_DemoActivityextends Activityimplements OnClickListener {
private Button firstDialog;
private Button senondDialog;
private Button thirdDialog;
private Button fourthDialog;
private Button fifthDialog;
static Toast mToast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
firstDialog = (Button) findViewById(R.id.btn_dialog01);
senondDialog = (Button) findViewById(R.id.btn_dialog02);
thirdDialog = (Button) findViewById(R.id.btn_dialog03);
fourthDialog = (Button) findViewById(R.id.btn_dialog04);
fifthDialog = (Button) findViewById(R.id.btn_dialog05);
firstDialog.setOnClickListener(this);
senondDialog.setOnClickListener(this);
thirdDialog.setOnClickListener(this);
fourthDialog.setOnClickListener(this);
fifthDialog.setOnClickListener(this);
}
/**
*
* Description: 按钮触发事件
* @param v
* @see android.view.View.OnClickListener#onClick(android.view.View)
*/
public void onClick(View v) {
if(v == firstDialog){
showDialog();
}else if(v == senondDialog){
showDialogSecond();
}else if(v ==thirdDialog){
showDialogThree();
}else if(v == fourthDialog){
showDialogFour();
}else if(v == fifthDialog){
showDialogFive();
}
}
/**
*
* Description:俩按钮对话框
*/
public void showDialog() {
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setMessage("你确定要退出吗?");
aBuilder.setTitle("提示");
aBuilder.setPositiveButton(R.string.sure,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.create().show();
}
/**
*
* Description:三个按钮的对话框
*/
private void showDialogSecond(){
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setIcon(R.drawable.ic_launcher);
aBuilder.setTitle("喜好调查");
aBuilder.setMessage("你喜欢李连杰的电影吗?");
aBuilder.setPositiveButton("很喜欢",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
showMessage(Dialog_DemoActivity.this,"很喜欢");
}
});
aBuilder.setNegativeButton("不喜欢",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
showMessage(Dialog_DemoActivity.this,"不喜欢");
}
});
aBuilder.setNeutralButton("一般",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
showMessage(Dialog_DemoActivity.this,"一般");
}
});
aBuilder.create().show();
}
private void showDialogThree(){
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setTitle("请输入");
aBuilder.setView(new EditText(Dialog_DemoActivity.this));
aBuilder.setPositiveButton(R.string.sure,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.create().show();
}
private void showDialogFour(){
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setTitle("复选框");
aBuilder.setMultiChoiceItems(new String[] { "Item1", color=#FF00FF>"Item2" }, null, null);
aBuilder.setPositiveButton(R.string.sure,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.create().show();
}
/**
*
* Description: 列表对话框
*/
private void showDialogFive(){
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setTitle("列表框");
aBuilder.setItems(new String[] { "Item1", color=#FF00FF>"Item2" }, null);
aBuilder.setPositiveButton(R.string.sure,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.create().show();
}
/**
*
* Description: 显示提示信息
* @param context
* @param str 提示信息的内容
*/
public synchronizedvoid showMessage(Contextcontext,String str) {
if (mToast == null) {
mToast = Toast.makeText(context,"", Toast.LENGTH_SHORT);
}
mToast.setText(str);
mToast.show();
}
}
===============================文件名: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:background="@drawable/img_main_bg"
android:orientation="vertical" >
<Button
android:id="@+id/btn_dialog01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_1" />
<Button
android:id="@+id/btn_dialog02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_2" />
<Button
android:id="@+id/btn_dialog03"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_3" />
<Button
android:id="@+id/btn_dialog04"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_4" />
<Button
android:id="@+id/btn_dialog05"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_5" />
</LinearLayout>
===================文件名:strings.xml==========================
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, Dialog_DemoActivity!</string>
<string name="app_name">Dialog_Demo</string>
<string name="dialog_1">First Dialog</string>
<string name="dialog_2">Second Dialog</string>
<string name="dialog_3">Third Dialog</string>
<string name="dialog_4">Fourth Dialog</string>
<string name="dialog_5">Fifth Dialog</string>
<string name="sure">确认</string>
</resources>
import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
/**
*
* <p>Title: Dialog_DemoActivity.java</p>
* <p>Description: 各种对话框示例</p>
* <p>Copyright: Copyright (c) 2011</p>
* <p>Company: Xawx Teachnology</p>
* <p>CreateTime: 2012-9-14 下午2:05:54</p>
*
* @author ygc
* @version %A%, %B%
* @since JDK1.6
* @CheckItem null
*/
public class Dialog_DemoActivityextends Activityimplements OnClickListener {
private Button firstDialog;
private Button senondDialog;
private Button thirdDialog;
private Button fourthDialog;
private Button fifthDialog;
static Toast mToast;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
firstDialog = (Button) findViewById(R.id.btn_dialog01);
senondDialog = (Button) findViewById(R.id.btn_dialog02);
thirdDialog = (Button) findViewById(R.id.btn_dialog03);
fourthDialog = (Button) findViewById(R.id.btn_dialog04);
fifthDialog = (Button) findViewById(R.id.btn_dialog05);
firstDialog.setOnClickListener(this);
senondDialog.setOnClickListener(this);
thirdDialog.setOnClickListener(this);
fourthDialog.setOnClickListener(this);
fifthDialog.setOnClickListener(this);
}
/**
*
* Description: 按钮触发事件
* @param v
* @see android.view.View.OnClickListener#onClick(android.view.View)
*/
public void onClick(View v) {
if(v == firstDialog){
showDialog();
}else if(v == senondDialog){
showDialogSecond();
}else if(v ==thirdDialog){
showDialogThree();
}else if(v == fourthDialog){
showDialogFour();
}else if(v == fifthDialog){
showDialogFive();
}
}
/**
*
* Description:俩按钮对话框
*/
public void showDialog() {
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setMessage("你确定要退出吗?");
aBuilder.setTitle("提示");
aBuilder.setPositiveButton(R.string.sure,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.create().show();
}
/**
*
* Description:三个按钮的对话框
*/
private void showDialogSecond(){
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setIcon(R.drawable.ic_launcher);
aBuilder.setTitle("喜好调查");
aBuilder.setMessage("你喜欢李连杰的电影吗?");
aBuilder.setPositiveButton("很喜欢",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
showMessage(Dialog_DemoActivity.this,"很喜欢");
}
});
aBuilder.setNegativeButton("不喜欢",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
showMessage(Dialog_DemoActivity.this,"不喜欢");
}
});
aBuilder.setNeutralButton("一般",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
showMessage(Dialog_DemoActivity.this,"一般");
}
});
aBuilder.create().show();
}
private void showDialogThree(){
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setTitle("请输入");
aBuilder.setView(new EditText(Dialog_DemoActivity.this));
aBuilder.setPositiveButton(R.string.sure,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.create().show();
}
private void showDialogFour(){
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setTitle("复选框");
aBuilder.setMultiChoiceItems(new String[] { "Item1", color=#FF00FF>"Item2" }, null, null);
aBuilder.setPositiveButton(R.string.sure,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.create().show();
}
/**
*
* Description: 列表对话框
*/
private void showDialogFive(){
AlertDialog.Builder aBuilder = new Builder(Dialog_DemoActivity.this);
aBuilder.setTitle("列表框");
aBuilder.setItems(new String[] { "Item1", color=#FF00FF>"Item2" }, null);
aBuilder.setPositiveButton(R.string.sure,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
aBuilder.create().show();
}
/**
*
* Description: 显示提示信息
* @param context
* @param str 提示信息的内容
*/
public synchronizedvoid showMessage(Contextcontext,String str) {
if (mToast == null) {
mToast = Toast.makeText(context,"", Toast.LENGTH_SHORT);
}
mToast.setText(str);
mToast.show();
}
}
===============================文件名: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:background="@drawable/img_main_bg"
android:orientation="vertical" >
<Button
android:id="@+id/btn_dialog01"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_1" />
<Button
android:id="@+id/btn_dialog02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_2" />
<Button
android:id="@+id/btn_dialog03"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_3" />
<Button
android:id="@+id/btn_dialog04"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_4" />
<Button
android:id="@+id/btn_dialog05"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/dialog_5" />
</LinearLayout>
===================文件名:strings.xml==========================
<?xml version="1.0" encoding="utf-8"?><resources> <string name="hello">Hello World, Dialog_DemoActivity!</string>
<string name="app_name">Dialog_Demo</string>
<string name="dialog_1">First Dialog</string>
<string name="dialog_2">Second Dialog</string>
<string name="dialog_3">Third Dialog</string>
<string name="dialog_4">Fourth Dialog</string>
<string name="dialog_5">Fifth Dialog</string>
<string name="sure">确认</string>
</resources>
=========================文件名:AndroidManifest.xml==============================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ygc.dialog.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Dialog_DemoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.ygc.dialog.activity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="10" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<activity
android:name=".Dialog_DemoActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
源码下载地址:源码下载
- Android 各种Dialog整理
- android 各种常用,不易记的dialog,等控件整理
- Android的各种Dialog
- Android Dialog资料整理
- android 各种常用,不易记的dialog,对话框,等控件整理
- 关于Android中的各种Dialog
- android轻量框架_各种Dialog
- android自定义dialog-各种可控制
- 【Android】自定义风格的各种dialog
- Study-android 各种dialog的学习总结
- 【Android】Dialog 对话框各种式样的制作
- android各种提示Dialog 弹出框
- Android中的各种样式的Dialog
- android dialog 收集整理集合 自己的dialog库
- android 单元测试之dialog测试链接整理
- Android Dialog的多种对话框整理案例
- android添加各种权限整理
- 整理Android各种框架文档
- Clojure:在REPL上实现一个简单的shell(三)
- JFreeChart在JSP中的应用实例
- 暑期第一次多校联合赛 I题 数学题
- 帮助客户创新
- 不公平的社会
- Android 各种Dialog整理
- sed简介【转】
- pic跨页 PCLATH
- 如何设置网页标题图标
- 通用版登录login_委托
- linux top命令
- android usb挂载分析----vold启动
- poj1734 - Sightseeing trip
- 防止独立ip虚拟主机被恶意解析的方法 canonical标签 百度