package com.example.seekbar;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Alert extends Activity {
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.alert);
noti();
}
private void noti(){
final NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
btn=(Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
private int NOTIFYID_1;
@SuppressWarnings("deprecation")
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// Notification notify=new Notification();
// notify.icon=R.drawable.img01;
// notify.tickerText="显示第一个通知";
// notify.when=System.currentTimeMillis(); //设置发送的时间
// notify.defaults=Notification.DEFAULT_ALL;
// notify.setLatestEventInfo(Alert.this, "无题", "每天进步一点点", null);
// notificationManager.notify(NOTIFYID_1, notify);
//第二个通知
Notification notify1=new Notification(R.drawable.img01,"显示第二个通知",System.currentTimeMillis());
notify1.flags|=Notification.FLAG_AUTO_CANCEL;
Intent i=new Intent(Alert.this,Alert.class);
PendingIntent pendingintent=PendingIntent.getActivity(Alert.this, 0, i, 0);
notify1.setLatestEventInfo(Alert.this, "通知", "查看详情信息", pendingintent);
notificationManager.notify(NOTIFYID_1, notify1);
}
});
}
//通过构造方法来创建吐司
private void clicktoast(){
btn=(Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//通过makeText();
//Toast.makeText(Alert.this, "这是通过maketext()创建的提示框", Toast.LENGTH_SHORT).show();
//通过构造方法
Toast toast=new Toast(Alert.this);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout ll=new LinearLayout(Alert.this);
ImageView iv=new ImageView(Alert.this);
iv.setImageResource(R.drawable.ic_launcher);
iv.setPadding(0,0, 5, 0);
ll.addView(iv);
TextView tv=new TextView(Alert.this);
tv.setText("这是通过构造方法创建的消息提示框");
ll.addView(tv);
toast.setView(ll);
toast.show();
}
});
}
}
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class Alert extends Activity {
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.alert);
noti();
}
private void noti(){
final NotificationManager notificationManager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
btn=(Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
private int NOTIFYID_1;
@SuppressWarnings("deprecation")
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
// Notification notify=new Notification();
// notify.icon=R.drawable.img01;
// notify.tickerText="显示第一个通知";
// notify.when=System.currentTimeMillis(); //设置发送的时间
// notify.defaults=Notification.DEFAULT_ALL;
// notify.setLatestEventInfo(Alert.this, "无题", "每天进步一点点", null);
// notificationManager.notify(NOTIFYID_1, notify);
//第二个通知
Notification notify1=new Notification(R.drawable.img01,"显示第二个通知",System.currentTimeMillis());
notify1.flags|=Notification.FLAG_AUTO_CANCEL;
Intent i=new Intent(Alert.this,Alert.class);
PendingIntent pendingintent=PendingIntent.getActivity(Alert.this, 0, i, 0);
notify1.setLatestEventInfo(Alert.this, "通知", "查看详情信息", pendingintent);
notificationManager.notify(NOTIFYID_1, notify1);
}
});
}
//通过构造方法来创建吐司
private void clicktoast(){
btn=(Button) findViewById(R.id.button1);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
//通过makeText();
//Toast.makeText(Alert.this, "这是通过maketext()创建的提示框", Toast.LENGTH_SHORT).show();
//通过构造方法
Toast toast=new Toast(Alert.this);
toast.setDuration(Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER, 0, 0);
LinearLayout ll=new LinearLayout(Alert.this);
ImageView iv=new ImageView(Alert.this);
iv.setImageResource(R.drawable.ic_launcher);
iv.setPadding(0,0, 5, 0);
ll.addView(iv);
TextView tv=new TextView(Alert.this);
tv.setText("这是通过构造方法创建的消息提示框");
ll.addView(tv);
toast.setView(ll);
toast.show();
}
});
}
}