您的位置:首页 > 移动开发 > Android开发

各种提示信息

2014-10-27 15:42 357 查看
package com.example.girl2;

import android.annotation.SuppressLint;

import android.app.Activity;

//import android.app.AlertDialog.Builder;

import android.app.Notification;

import android.app.Notification.Builder;

import android.app.NotificationManager;

import android.app.ProgressDialog;

import android.graphics.BitmapFactory;

import android.media.AudioManager;

import android.media.SoundPool;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class SoundPoolActivity extends Activity {
private SoundPool soundPool;
private int soundId;
private Button btn;

@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.fragment_main);
btn = (Button) findViewById(R.id.btn);

//SoundPool的初始化的操作要在onCreate方法中执行
soundPool = new SoundPool(5, AudioManager.STREAM_MUSIC, 0);//arg0:SoundPool中的音频资源最多数量,arg1:音频流类型,arg2:没有用,用于扩展的
soundId = soundPool.load(this, R.raw.sound1, 1);//加载声音资源

}

/**
* 在通知栏上显示通知信息
*/
@SuppressLint("NewApi")
public void click06(View view){
//1.获取到手机系统里面的通知管理器
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
//2.实例化 notification 表示通知的具体内容
Notification.Builder builder = new Builder(this);
builder.setContentTitle("我是notification的标题 ")

        .setContentText("我是notification的内容")

        .setSmallIcon(R.drawable.notification)

        .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher));
Notification  notification = builder.build();
nm.notify(0, notification);

}

public void play(View v){
soundPool.play(soundId, 1.0f, 1.0f, 0, -1, 2.0f);//arg0:待播放音频文件的id值,arg1:左声道的值,arg2:右声道的值,arg3:改音频的优先级,arg4:是否循环0,不循环,,,-1循环,arg5:播放速率
btn.setEnabled(false);
}

/**
* 进度对话框
* @param view
*/
public void click04(View view){
ProgressDialog pd = new ProgressDialog(this);

pd.setTitle("提示");
pd.setMessage("正在加载。。。。");
pd.show();
}

/**
* 进度条对话框
* @param view
*/
public void click05(View view){
final ProgressDialog pd = new ProgressDialog(this);
pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
pd.setTitle("提示进度信息oowwwwwwwwww");
pd.setMax(100);
pd.show();
new Thread(){
@Override
public void run() {
for(int i= 1;i<101;i++){
pd.setProgress(i);
try {
Thread.sleep(50);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
pd.dismiss();
};
}.start();

}

/**
* 多选对话框
* @param view
*/
/*public void click03(View view){
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("多选对话框演示");
builder.setIcon(R.drawable.ic_launcher);
final String[] items = new String[]{"条目一","条目二","条目三","条目四","条目五","条目六","条目七","条目八","条目九","条目十"};
boolean[] state = new boolean[]{true,false,true,false,true,false,true,false,true,true};
builder.setMultiChoiceItems(items, state, new OnMultiChoiceClickListener() {

@Override
public void onClick(DialogInterface arg0, int index, boolean arg2) {
String text =arg2?"选中了":"取消选中";
Toast.makeText(SoundPoolActivity.this, items[index]+text, 0).show();

}
});
builder.setNegativeButton("取消", new OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub

}
});
builder.show();
}*/

/**
* 单选对话框
* @param view
*/
public void click02(View view){
//创建一个对话框构建者实例
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("单选对话框");
builder.setIcon(R.drawable.ic_launcher);
final String[] items = new String[]{"条目一","条目二","条目三","条目四","条目五","条目六","条目七","条目八","条目九","条目十"};
builder.setSingleChoiceItems(items, 1, new OnClickListener() {//arg0:各条目字符串数组,arg1:默认选择的条目,arg2:当条目被点击时添加的监听事件

@Override
public void onClick(DialogInterface dialog, int index) {
// TODO Auto-generated method stub
Toast.makeText(SoundPoolActivity.this, items[index]+"被点击了,,", 0).show();
Intent intent = new Intent(SoundPoolActivity.this, MainActivity.class);
startActivity(intent);
//dialog.dismiss();//当点击某一条目后对话框隐藏
}
});
builder.setNegativeButton("取消", new OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub

}
});

builder.show();//将对话框显示出来,底层是用下面两句完成的

// AlertDialog dialog2 = builder.create();

// dialog2.show();
}

/**
* 点击显示对话框
* @param view
*/
public void click01(View view){
//创建一个对话框实例,
AlertDialog.Builder builder = new Builder(this);
builder.setTitle("显示对话框");
builder.setIcon(R.drawable.alarm1);
builder.setMessage("你确定要升级此软件吗?");
builder.setPositiveButton("确定", new OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int arg1) {
Toast.makeText(SoundPoolActivity.this, "确定按钮被点击了。。。。", 0).show();

}
});
builder.setNegativeButton("取消", new OnClickListener() {

@Override
public void onClick(DialogInterface arg0, int arg1) {
// TODO Auto-generated method stub

}
});
AlertDialog dialog = builder.create();//通过对话框builder将对话框创建出来
dialog.show();//显示对话框
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息