目标:
Notification content的样式为左边是提示文字,右边为Button,单击Button激活相应Intent
材料:
1.自定义布局 * 1
方法:过程比较简单,这里直接贴上代码
public class NotificationCustom extends Activity {
private NotificationManager notificationManager;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.notification_custom);
//获取到系统的notificationManager
notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
Notification nf = new Notification(R.drawable.icon, "this is mini title", System.currentTimeMillis());
Intent intent = new Intent(this,NextActicity.class);
PendingIntent pd = PendingIntent.getActivity(this, 0, intent, 0);
nf.contentIntent = pendingIntent;
//自定义界面
RemoteViews rv = new RemoteViews(getPackageName(), R.layout.notification_view);
rv.setTextViewText(R.id.nf_tv_content, "click the button");
rv.setOnClickPendingIntent(R.id.nf_btn_next, pd);
nf.contentView = rv;
//把定义的notification 传递给 notificationmanager
nf.notify(NOTIFICATION_ID, notification);
}
}