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

相关内容

热门资讯

WPK链接窍要!wepoker... WPK链接窍要!wepoker透视方法,德州微扑克原来存在有辅助插件1、玩家可以在wepoker透视...
WPK俱乐部阶段!wepoke... WPK俱乐部阶段!wepoker线上大神,德州微扑克一直真的是有透视神器wepoker线上大神透视方...
WPK透视版手筋!wepoke... WPK透视版手筋!wepoker软件靠谱么,德州微扑克其实是真的有辅助攻略一、wepoker软件靠谱...
WPK德州局烘培!wepoke... WPK德州局烘培!wepoker有辅助插件吗,德州微扑克果然真的有辅助器插件1.wepoker有辅助...
WPK方法演示!aapoker... WPK方法演示!aapoker辅助功能,德州微扑克竟然是真的有辅助攻略aapoker辅助功能透视方法...
WPK安卓妙招!wepoker... WPK安卓妙招!wepoker轻量版有透视吗,德州微扑克切实有辅助工具1)wepoker轻量版有透视...
WPK俱乐部手段!wepoke... WPK俱乐部手段!wepoker辅助脚本,德州微扑克真是真的有辅助软件;1.wepoker辅助脚本 ...
WPK辅助器指南书!aapok... WPK辅助器指南书!aapoker辅助工具存在吗,德州微扑克真是有透视挂插件1、任何aapoker辅...
WPK靠谱手筋!wepoker... WPK靠谱手筋!wepoker养号规律,德州微扑克真是是真的有透视挂app亲,关键说明,wepoke...
WPK控制牌课程!wepoke... WPK控制牌课程!wepoker插件功能辅助器,德州微扑克一贯真的有透视挂工具1、wepoker插件...