使用RemoteViews自定义Notification

目标:

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);
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值