Dialog的几种方式
来源:互联网 发布:mac微信文件保存位置 编辑:程序博客网 时间:2024/05/09 08:48
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class NotifyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notify);
}
int count ;
/**
* android对用户通知方式
* 1、Toast
*/
/**
* @param view
*/
public void onMyClick(View view){
int id = view.getId() ;
switch(id){
case R.id.btn_toast:
//显示多个
// showToast();
//显示一个
showToastOnly() ;
break ;
case R.id.btn_dialog:
//警告对话框
showAlertDialog();
//进度条对话框
// showProgressDialog();
break ;
case R.id.btn_notification:
//状态栏通知
showNotificationWithAPI3() ;
// showNotificationWithAPI16();
break ;
}
}
private void showNotificationWithAPI3() {
//1.创建Notification对象
Notification notification = new Notification(R.drawable.ic_launcher, "提示", System.currentTimeMillis()) ;
//2.设置数据
PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent(this, NotifyActivity.class), 0) ;
notification.setLatestEventInfo(this, "标题", "内容", pIntent) ;
//3.显示
//3.1获取系统的状态栏通知服务
NotificationManager notificatioManager
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE) ;
//3.2显示我们的Notification
notificatioManager.notify(1000, notification) ;
}
@SuppressLint("NewApi")
/*private void showNotificationWithAPI21() {
//这里是新的创建方式:
//1.创建Builder对象
Notification.Builder builder = new Notification.Builder(this) ;
//2.设置属性
builder
.setTicker("Ticker")
.setContentText("内容文字")
.setContentTitle("内容标题");
//创建一个PendingIntent,持有一个Intent对象,当我们调用send方法时,这个Intent才会去启动某个系统组件。
//要启动哪种系统组件,我们需要在创建PendingIntent时,调用对应的方法,创建PendingIntent.
Intent intent = new Intent(this, NotifyActivity.class) ;
*//**
* 参数1: context
* 参数2: 无用
* 参数3:Intent
* 参数4:依据PendingIntent的4中常量值,选择一种处理标志
* *//*
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) ;
//将pendingintent设置给notification
builder.setContentIntent(pIntent) ;
//3.创建Notification对象
Notification notification = builder.build() ;
//4.显示
//4.1获取系统的状态栏通知服务
NotificationManager notificatioManager
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE) ;
//4.2显示我们的Notification
notificatioManager.notify(1000, notification) ;
}*/
private void showProgressDialog() {
//1.创建对象
ProgressDialog dialog = new ProgressDialog(this) ;
//2.设置属性
dialog.setTitle("警告") ;
dialog.setMessage("______");
//3.显示
dialog.show() ;
}
private void showAlertDialog() {
//使用AlterDialog
//1.创建Builder对象
AlertDialog.Builder builder = new AlertDialog.Builder(this) ;
//2.通过Builder对象,创建AlertDialog对象
builder
.setTitle("标题")
.setMessage("这里是内容")
.setPositiveButton("确定", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
System.out.println("是");
}
})
.setNeutralButton("不知道", null)
.setNegativeButton("不是", null);
//创建AlertDialog
AlertDialog dialog = builder.create() ;
//显示AlertDialog
dialog.show() ;
//将显示的AlertDialog消失
// dialog.dismiss() ;
}
private void showToast() {
//通过静态方法获取对象
Toast toast = Toast.makeText(NotifyActivity.this, "我是土司 NO."+(count++), Toast.LENGTH_SHORT) ;
//显示此通知
toast.show() ; //这里系统会使用一个队列来管理将要显示的Toast,如果已经有一个Toast在显示,其他的Toast需要
//依次等待在队列中,然后先进先出的一个一个显示。
}
private Toast toast ;
private void showToastOnly() {
//通过静态方法获取对象
if(toast==null)
toast = Toast.makeText(NotifyActivity.this, "我是土司 NO."+(count++), Toast.LENGTH_SHORT) ;
//对已经创建好的Toast进行操作
toast.setText("我是土司 NO."+(count++)) ;
//显示此通知
toast.show() ; //这里系统会使用一个队列来管理将要显示的Toast,如果已经有一个Toast在显示,其他的Toast需要
//依次等待在队列中,然后先进先出的一个一个显示。
}
}
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class NotifyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notify);
}
int count ;
/**
* android对用户通知方式
* 1、Toast
*/
/**
* @param view
*/
public void onMyClick(View view){
int id = view.getId() ;
switch(id){
case R.id.btn_toast:
//显示多个
// showToast();
//显示一个
showToastOnly() ;
break ;
case R.id.btn_dialog:
//警告对话框
showAlertDialog();
//进度条对话框
// showProgressDialog();
break ;
case R.id.btn_notification:
//状态栏通知
showNotificationWithAPI3() ;
// showNotificationWithAPI16();
break ;
}
}
private void showNotificationWithAPI3() {
//1.创建Notification对象
Notification notification = new Notification(R.drawable.ic_launcher, "提示", System.currentTimeMillis()) ;
//2.设置数据
PendingIntent pIntent = PendingIntent.getActivity(this, 0, new Intent(this, NotifyActivity.class), 0) ;
notification.setLatestEventInfo(this, "标题", "内容", pIntent) ;
//3.显示
//3.1获取系统的状态栏通知服务
NotificationManager notificatioManager
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE) ;
//3.2显示我们的Notification
notificatioManager.notify(1000, notification) ;
}
@SuppressLint("NewApi")
/*private void showNotificationWithAPI21() {
//这里是新的创建方式:
//1.创建Builder对象
Notification.Builder builder = new Notification.Builder(this) ;
//2.设置属性
builder
.setTicker("Ticker")
.setContentText("内容文字")
.setContentTitle("内容标题");
//创建一个PendingIntent,持有一个Intent对象,当我们调用send方法时,这个Intent才会去启动某个系统组件。
//要启动哪种系统组件,我们需要在创建PendingIntent时,调用对应的方法,创建PendingIntent.
Intent intent = new Intent(this, NotifyActivity.class) ;
*//**
* 参数1: context
* 参数2: 无用
* 参数3:Intent
* 参数4:依据PendingIntent的4中常量值,选择一种处理标志
* *//*
PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) ;
//将pendingintent设置给notification
builder.setContentIntent(pIntent) ;
//3.创建Notification对象
Notification notification = builder.build() ;
//4.显示
//4.1获取系统的状态栏通知服务
NotificationManager notificatioManager
= (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE) ;
//4.2显示我们的Notification
notificatioManager.notify(1000, notification) ;
}*/
private void showProgressDialog() {
//1.创建对象
ProgressDialog dialog = new ProgressDialog(this) ;
//2.设置属性
dialog.setTitle("警告") ;
dialog.setMessage("______");
//3.显示
dialog.show() ;
}
private void showAlertDialog() {
//使用AlterDialog
//1.创建Builder对象
AlertDialog.Builder builder = new AlertDialog.Builder(this) ;
//2.通过Builder对象,创建AlertDialog对象
builder
.setTitle("标题")
.setMessage("这里是内容")
.setPositiveButton("确定", new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
System.out.println("是");
}
})
.setNeutralButton("不知道", null)
.setNegativeButton("不是", null);
//创建AlertDialog
AlertDialog dialog = builder.create() ;
//显示AlertDialog
dialog.show() ;
//将显示的AlertDialog消失
// dialog.dismiss() ;
}
private void showToast() {
//通过静态方法获取对象
Toast toast = Toast.makeText(NotifyActivity.this, "我是土司 NO."+(count++), Toast.LENGTH_SHORT) ;
//显示此通知
toast.show() ; //这里系统会使用一个队列来管理将要显示的Toast,如果已经有一个Toast在显示,其他的Toast需要
//依次等待在队列中,然后先进先出的一个一个显示。
}
private Toast toast ;
private void showToastOnly() {
//通过静态方法获取对象
if(toast==null)
toast = Toast.makeText(NotifyActivity.this, "我是土司 NO."+(count++), Toast.LENGTH_SHORT) ;
//对已经创建好的Toast进行操作
toast.setText("我是土司 NO."+(count++)) ;
//显示此通知
toast.show() ; //这里系统会使用一个队列来管理将要显示的Toast,如果已经有一个Toast在显示,其他的Toast需要
//依次等待在队列中,然后先进先出的一个一个显示。
}
}
0 0
- Dialog的几种方式
- 自定义Dialog的几种实现方式
- QT4 Creator创建基本的Dialog的几种方式
- Android底部dialog的几种实现方式
- Android--Dialog,Dialog 的几种使用方法
- Dialog的几种用法
- 几种常见的Dialog
- android dialog常见的几种用法
- Android 对话框(Dialog)的几种用法。
- Dialog的几种形式 Android开发
- Android dialog的几种形式
- Android 对话框(Dialog)的几种用法。
- 几种简单的Dialog对话框
- 自定义dialog的两种方式
- 自定义Dialog的两种实现方式
- dialog全局显示的两种方式
- 定制dialog的方式
- dialog的activity方式
- 利用openssl库进行RSA加密
- Python读写文件的方式
- 清除行列
- Linux中一些文件缩写名词stc/bin/rt/tty/dev
- UVa 10140 - Prime Distance
- Dialog的几种方式
- C共用体
- 机器学习之——归一化
- 发布地图打印服务注意事项
- CentOS安装Haproxy源码编译安装
- Java利用Properties类操作属性文件
- hdu2222
- linux下tomcat7 catalina.out 文件分割
- js中获取url?后面的参数,以及其他参数的获取