1.介绍
2.常用属性
3.java后台代码
package com.lucky.test30notification; import android.app.Notification; import android.app.NotificationManager; import android.os.Build; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity { Button button1; Button button2; NotificationManager notificationManager; //定义一个通知管理器 @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button1=findViewById(R.id.button); button2=findViewById(R.id.button2); //实例化通知管理器 notificationManager= (NotificationManager) getSystemService(NOTIFICATION_SERVICE); button1.setOnClickListener(new View.OnClickListener() { @RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN) @Override public void onClick(View v) { Notification.Builder builder=new Notification.Builder(MainActivity.this); builder.setSmallIcon(R.mipmap.img07); //设置图标 builder.setTicker("新消息");//消息来时的提示内容 builder.setContentTitle("新通知");//设置通知题目 builder.setContentText("虎扑ios上线了");//设置通知内容 builder.setDefaults(Notification.DEFAULT_ALL);//设置默认格式 notificationManager.notify(0x01,builder.build()); } }); button2.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { notificationManager.cancel(0x01); //取消通知 } }); } }