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

相关内容

热门资讯

透视挂!aapoker辅助怎么... 透视挂!aapoker辅助怎么用(透视)开挂辅助挂(都是真的有挂)-哔哩哔哩1、让任何用户在无需aa...
透视透视!wepoker开脚本... 透视透视!wepoker开脚本视频,wepoker永久免费脚本,操作教程(本来存在有挂)-哔哩哔哩1...
透视规律!德扑之心免费透视(透... 透视规律!德扑之心免费透视(透视)开挂辅助app(原来是真的挂)-哔哩哔哩透视规律!德扑之心免费透视...
透视好牌!wepoker透视脚... 透视好牌!wepoker透视脚本免费下载,wpk俱乐部怎么辅助,阶段教程(一贯是有挂)-哔哩哔哩1、...
透视辅助!wpk模拟器是什么(... 透视辅助!wpk模拟器是什么(透视)开挂辅助app(好像真的是有挂)-哔哩哔哩1、下载好wpk模拟器...
透视能赢!aapoker免费透... 透视能赢!aapoker免费透视脚本,wepoker怎么开辅助,窍要教程(原来真的有挂)-哔哩哔哩1...
透视靠谱!wpk系统是否存在辅... 透视靠谱!wpk系统是否存在辅助行为(透视)开挂辅助攻略(一贯有挂)-哔哩哔哩1、让任何用户在无需w...
透视实锤!约局吧德州可以透视吗... 透视实锤!约局吧德州可以透视吗,黑侠破解wepoker,攻略教程(本来有挂)-哔哩哔哩1、约局吧德州...
透视胜率!wepoker可以透... 透视胜率!wepoker可以透视码(透视)开挂辅助软件(切实是有挂)-哔哩哔哩在进入wepoker可...
透视透视!hhpoker德州真... 透视透视!hhpoker德州真的假的,拱趴大菠萝万能挂,举措教程(切实有挂)-哔哩哔哩1、操作简单,...