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)德普之星辅助...
透视好牌!hhpoker德州机... 透视好牌!hhpoker德州机器人(透视)切实存在有辅助辅助器(有挂秘诀)-哔哩哔哩1、hhpoke...
透视计算!德州局怎么透视(透视... 透视计算!德州局怎么透视(透视)好像真的有辅助安装(新版有挂)-哔哩哔哩1、操作简单,无需德州局怎么...
突发!epoker透视(透视)... 突发!epoker透视(透视)竟然真的是有辅助app(有挂实锤)-哔哩哔哩1、许多玩家不知道epok...
日前!pokemmo辅助器手机... 日前!pokemmo辅助器手机版下载(透视)一直有辅助辅助器(竟然有挂)-哔哩哔哩1、进入到poke...
据玩家消息!wepoker轻量... 据玩家消息!wepoker轻量版有透视吗(透视)总是有辅助平台(有挂详情)-哔哩哔哩1、wepoke...
更值得关注的是!wepoker... 更值得关注的是!wepoker怎么看牌型(透视)好像真的是有辅助软件(有挂秘诀)-哔哩哔哩1、实时w...
透视黑科技!hhpoker怎么... 透视黑科技!hhpoker怎么破解(透视)总是真的是有辅助安装(真的有挂)-哔哩哔哩1、首先打开hh...
透视私人局!hhpoker是正... 透视私人局!hhpoker是正规的吗(透视)确实存在有辅助下载(有挂功能)-哔哩哔哩1)hhpoke...
最终!哈糖大菠萝破解器(透视)... 最终!哈糖大菠萝破解器(透视)都是存在有辅助下载(有挂方式)-哔哩哔哩1、每一步都需要思考,不同水平...