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

相关内容

热门资讯

五分钟手段!we poker辅... 五分钟手段!we poker辅助器(透视)好像是有辅助透视(哔哩哔哩)1、完成we poker辅助器...
第8分钟辅助!财神十三张福袋多... 您好,财神十三张福袋多少钱这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
第十分钟指南书!wepoker... 第十分钟指南书!wepoker透视脚本免费app(透视)本来是真的有辅助工具(哔哩哔哩)在进入wep...
第九分钟辅助!大唐辅助器,功夫... 第九分钟辅助!大唐辅助器,功夫川麻辅助(好像存在有辅助修改器)-哔哩哔哩第九分钟辅助!大唐辅助器,功...
两分钟手段!wepoker手机... 两分钟手段!wepoker手机助手(透视)好像真的是有辅助神器(哔哩哔哩)1、操作简单,无需wepo...
3分钟脚本!广西老友修改器,四... 3分钟脚本!广西老友修改器,四川游戏家园辅助软件下载(真是存在有辅助修改器)-哔哩哔哩该软件可以轻松...
第七分钟诀窍!hhpoker是... 第七分钟诀窍!hhpoker是正规的吗(透视)果然是有辅助神器(哔哩哔哩);1、打开软件启动之后找到...
第五分钟操作!we-poker... 您好,we-poker软件这款游戏可以开挂的,确实是有挂的,需要了解加去威信【136704302】很...
第三分钟插件!蘑菇辅助网,哥哥... 第三分钟插件!蘑菇辅助网,哥哥打大a有没有辅助(一直存在有辅助软件)-哔哩哔哩哥哥打大a有没有辅助能...
2分钟总结!wepoker私人... 2分钟总结!wepoker私人局怎么玩(透视)确实真的有辅助脚本(哔哩哔哩)1、操作简单,无需wep...