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

相关内容

热门资讯

一分钟教你!创思维激k破解更新... 一分钟教你!创思维激k破解更新内容,创乐源辅助软件(有挂开挂辅助脚本);无需打开直接搜索打开薇:13...
透明有挂!科乐填大坑辅助视频,... 透明有挂!科乐填大坑辅助视频,hhpoker真能买到挂吗-原本有挂开挂辅助工具;无需打开直接搜索微信...
重大通报!浙江游戏大厅游戏辅助... 您好:浙江游戏大厅游戏辅助器这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用...
透视好友!福建十三水辅助,po... 透视好友!福建十三水辅助,pokermaster辅助器-原先有挂开挂辅助工具;无需打开直接搜索薇:1...
一分钟了解!陕西三代二辅助器,... 您好:陕西三代二辅助器这款游戏可以开挂的,确实是有挂的,很多玩家在这款游戏中打牌都会发现很多用户的牌...
透视辅助!微信游戏决胜游戏辅助... 透视辅助!微信游戏决胜游戏辅助,pokemmo手机版脚本免费-素来有挂开挂辅助器;无需打开直接搜索加...
终于懂了!四川乐易麻将辅助脚本... 终于懂了!四川乐易麻将辅助脚本,萍乡滚筒四幅攻略(有挂开挂辅助器);无需打开直接搜索微信(13670...
透明讲解!微信小程序免费黑科技... 微信小程序免费黑科技是一款可以让一直输的玩家,快速成为一个“必胜”的ai辅助神器,有需要的用户可以加...
推荐一款!情怀游戏字牌辅助,花... 推荐一款!情怀游戏字牌辅助,花花生活圈怎么开挂(有挂开挂辅助神器);无需打开直接搜索加薇136704...
透视模拟器!小松宿松游戏辅助,... 透视模拟器!小松宿松游戏辅助,pokermaster破解版-原生有挂开挂辅助下载;无需打开直接搜索微...