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

相关内容

热门资讯

透视法子!wepoker软件辅... 透视法子!wepoker软件辅助程序,wepoker私人局透视教程(透视)真是真的是有脚本插件(哔哩...
透视积累!德扑之心免费透视,德... 透视积累!德扑之心免费透视,德普之星透视辅助软件是真的吗(透视)其实是有脚本挂(哔哩哔哩)1、德普之...
透视积累!aapoker插件,... 透视积累!aapoker插件,aapoker透视怎么用(透视)切实是真的透视软件(哔哩哔哩)1、aa...
透视指南!hhpoker作必弊... 透视指南!hhpoker作必弊码,sohoo poker辅助器(透视)都是存在有挂(哔哩哔哩)该软件...
透视手段!wepoker轻量版... 透视手段!wepoker轻量版有透视吗,wepoker智能辅助插件(透视)果然真的是有透视app(哔...
透视模块!wepoker透视脚... 透视模块!wepoker透视脚本下载,WePOker有没有透视方法(透视)真是是有透视器(哔哩哔哩)...
透视绝活!德州局怎么透视,wp... 透视绝活!德州局怎么透视,wpk有那种辅助吗(透视)真是是真的挂(哔哩哔哩)1、打开软件启动之后找到...
透视操作!hhpoker辅助挂... 透视操作!hhpoker辅助挂是真的吗,hhpoker德州真的假的(透视)切实有挂(哔哩哔哩)亲,关...
透视绝活!德州局怎么透视,wp... 透视绝活!德州局怎么透视,wpk有那种辅助吗(透视)真是真的有挂(哔哩哔哩)1、首先打开wpk有那种...
透视指南!wepoker好友局... 透视指南!wepoker好友局透视,购买wepoker模拟器(透视)一直真的有挂(哔哩哔哩)1、在w...