Android通知如何实现同时包含SeekBar和ProgressBar的FrameLayout?
创始人
2024-08-21 19:00:44
0

首先,需要在布局文件中定义一个FrameLayout,并在其中添加一个SeekBar和一个ProgressBar。然后,通过RemoteViews将布局文件添加到通知中。

以下是示例代码:

  1. 布局文件(notification_layout.xml)


    

     


  1. RemoteViews方法(createNotification())
private void createNotification() {
    // 创建RemoteViews
    RemoteViews notificationLayout = new RemoteViews(getPackageName(), R.layout.notification_layout);
    
    // 获取SeekBar和ProgressBar的ID
    int seekBarId = R.id.seek_bar;
    int progressBarId = R.id.progress_bar;
    
    // 设置SeekBar和ProgressBar的更新事件
    notificationLayout.setOnClickPendingIntent(seekBarId, getPendingIntentForSeekBar());
    notificationLayout.setOnClickPendingIntent(progressBarId, getPendingIntentForProgressBar());

    // 创建Notification
    NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_launcher_foreground)
            .setContentTitle("Notification Title")
            .setContentText("Notification Text")
            .setPriority(NotificationCompat.PRIORITY_HIGH)
            .setAutoCancel(true)
            .setCustomContentView(notificationLayout)
            .setColor(ContextCompat.getColor(this, R.color.colorPrimary))
            .setOnlyAlertOnce(true);
    
    Notification notification = builder.build();

    // 显示通知
    NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
    notificationManager.notify(NOTIFICATION_ID, notification);
}

其中,getPendingIntentForSeekBar()和getPendingIntentForProgressBar()是两个用于设置

相关内容

热门资讯

查到实测!xpoker辅助神器... 查到实测!xpoker辅助神器,wepoker私局辅助,果然是真的有挂(有挂攻略)查到实测!xpok...
玩家交流!werplan怎么作... 玩家交流!werplan怎么作弊,cloudpoker怎么开挂,切实是真的有挂(有挂神器)1、许多玩...
今日公布!wepoker轻量版... 今日公布!wepoker轻量版有透视吗,wepoker透视脚本视频,竟然真的有挂(有挂详情)1、该软...
科技分享!wepoker免费透... 科技分享!wepoker免费透视脚本,约局吧德州可以透视吗,切实真的是有挂(有挂头条)1)wepok...
技术分享!wepoker辅助器... 技术分享!wepoker辅助器官方,约局吧德州真的存在透视吗,本来真的有挂(有挂分享)1、wepok...
研究成果!werplan怎么作... 研究成果!werplan怎么作弊,wepokerplus透视脚本免费,总是真的有挂(有挂技术)1、研...
热点推荐!wpk俱乐部怎么作弊... 热点推荐!wpk俱乐部怎么作弊,sohoo辅助,本来是有挂(有挂方法)暗藏猫腻,小编详细说明破解器有...
热点讨论!aapoker安装包... 热点讨论!aapoker安装包怎么使用,hhpkoer辅助挂是真的吗,竟然是真的有挂(有挂头条)1、...
科普!WePoKer辅助器,拱... 科普!WePoKer辅助器,拱趴大菠萝有挂吗,总是真的是有挂(有挂细节)1、下载好正确养号方法之后点...
玩家必备科普!wpk俱乐部辅助... 玩家必备科普!wpk俱乐部辅助器,wepoker亲友圈有用吗,切实有挂(新版有挂)亲,关键说明,透视...