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()是两个用于设置

相关内容

热门资讯

透视辅助!蜜瓜大厅辅助免费下载... 透视辅助!蜜瓜大厅辅助免费下载"曝光辅助技巧"原来真的有挂(哔哩哔哩)1、蜜瓜大厅辅助免费下载有没有...
透视规律!皇豪互众智能辅助器破... 透视规律!皇豪互众智能辅助器破解"解迷辅助app"一贯真的是有挂(哔哩哔哩)1、皇豪互众智能辅助器破...
有了最新消息!传送屋辅助器官方... 有了最新消息!传送屋辅助器官方入口在哪里"开挂辅助技巧"真是真的有挂(哔哩哔哩)1、传送屋辅助器官方...
突发!余干中至小程序辅助器免费... 突发!余干中至小程序辅助器免费"开挂辅助神器"一贯存在有挂(哔哩哔哩);1、金币登录送、破产送、升级...
据统计!wepoker免费脚本... 据统计!wepoker免费脚本"辅助辅助脚本"其实真的是有挂(哔哩哔哩)1、起透看视 wepoker...
透视系统!四川皮皮辅助&quo... 透视系统!四川皮皮辅助"关于辅助攻略"切实是真的有挂(哔哩哔哩)1、下载好四川皮皮辅助正确养号方法之...
透视实锤!新上游拼十辅助&qu... 透视实锤!新上游拼十辅助"解迷辅助技巧"切实真的是有挂(哔哩哔哩)1、新上游拼十辅助辅助软件下载优化...
黑科技辅助挂!丽水都莱有辅助吗... 黑科技辅助挂!丽水都莱有辅助吗"透视辅助技巧"一直确实有挂(哔哩哔哩)一、丽水都莱有辅助吗可以开透视...
透视了解!熊猫挂机辅助下载&q... 透视了解!熊猫挂机辅助下载"解密辅助挂"其实真的是有挂(哔哩哔哩)1、熊猫挂机辅助下载透视辅助软件激...
据通报!广西老友玩辅助&quo... 您好,广西老友玩辅助这款游戏可以开挂的,确实是有挂的,需要了解加去威信【485275054】很多玩家...