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、不需要AI权限,帮...
总算了解!欢乐对决辅助菜单,榕... 总算了解!欢乐对决辅助菜单,榕城510k有没有挂,技巧教程(揭秘有挂)-哔哩哔哩;1、超多福利:超高...
揭秘攻略!乐乐围棋入门辅助,新... 揭秘攻略!乐乐围棋入门辅助,新久久辅助器,系统教程(今日头条)-哔哩哔哩;小薇(透视辅助)致您一封信...
我来分享!决胜游戏辅助器,皮皮... 《我来分享!决胜游戏辅助器,皮皮跑子胡子修改器,攻略教程!(有挂细节)-哔哩哔哩》 皮皮跑子胡子修改...
我来教教大家!蜀山四川破解好友... 我来教教大家!蜀山四川破解好友版辅助,邯郸胡乐修改器,揭秘攻略(有挂猫腻)-哔哩哔哩;人气非常高,a...
透视有挂!泸州大二新手攻略,新... 【福星临门,好运相随】;透视有挂!泸州大二新手攻略,新九哥开挂,线上教程(发现有挂)-哔哩哔哩;暗藏...
玩家攻略推荐!宝宝浙江辅助器,... 玩家攻略推荐!宝宝浙江辅助器,新海贝之城脚本,曝光教程(有挂细节)-哔哩哔哩;1、很好的新海贝之城脚...
科普常识!上饶辅助,龙江填大坑... 科普常识!上饶辅助,龙江填大坑视频攻略,细节揭秘(有挂秘籍)-哔哩哔哩;超受欢迎的龙江填大坑视频攻略...
让我来分享经验!牛总管辅助方法... 让我来分享经验!牛总管辅助方法,葫芦娃七子降妖破解版,玩家教你(有挂神器)-哔哩哔哩;1、完成葫芦娃...
重大通报!葫芦娃辅助修改器下载... 重大通报!葫芦娃辅助修改器下载,天天飞小鸡辅助,攻略教程!(果真有挂)-哔哩哔哩;是一款可以让一直输...