Android锁屏通知自定义视图带波纹和双击

Android锁屏通知自定义视图带波纹和双击,第1张

概述我正在使用 Android应用程式.这最后使用通过锁定屏幕上显示的自定义视图的通知.不幸的是,当我像其他通知一样,我无法获得纹波和高程效果.此外,单触发触发我已配置的意图,而其他通知需要双击. 我在Github上放了一个最小的项目示例: https://github.com/lpellegr/android-notification-custom-example 应用示例提供了两个按钮来发布通知: 我正在使用 Android应用程式.这最后使用通过锁定屏幕上显示的自定义视图的通知.不幸的是,当我像其他通知一样,我无法获得纹波和高程效果.此外,单触发触发我已配置的意图,而其他通知需要双击.

我在Github上放了一个最小的项目示例:

https://github.com/lpellegr/android-notification-custom-example

应用示例提供了两个按钮来发布通知:一个使用自定义视图并受到上述问题的影响,另一个使用默认系统视图的通知与预期的行为.

任何关于如何获得纹波和高程效果以及双击行为(通过保持定制视图)的想法是受欢迎的.

PS:我正在针对API 19,我想为通知使用自定义视图布局以及setonClickPendingIntent,因为只有此侦听器允许打开任何安全模式的设备的活动.

解决方法 从方法publishNotificationWithCustomVIEw中删除setonClickPendingIntent,并将setContentIntent添加到通知构建器中:
private voID publishNotificationWithCustomVIEw() {    String Title = "Notification Custom VIEw";    String content = "No ripple effect,no elevation,single tap trigger";    Context context = getApplicationContext();    NotificationCompat.Builder builder =            new NotificationCompat.Builder(context)                    .setWhen(System.currentTimeMillis())                    .setDefaults(DEFAulT_ALL)                    .setSmallicon(R.mipmap.ic_launcher)                    .setPriority(NotificationCompat.PRIORITY_HIGH)                    .setonlyAlertOnce(true)                    .setautoCancel(false)                    .setcolor(ContextCompat.getcolor(context,R.color.colorAccent))                    .setContentTitle(Title)                    .setContentText(content)                    .setongoing(true)                    .setcategory(NotificationCompat.category_ALARM)                    .setVisibility(NotificationCompat.VISIBIliTY_PUBliC)                    .setContentIntent(createLockscreenNotificationPendingIntent(context));    int notificationLayoutResID = R.layout.lock_screen_notification;    // using folder layout-vX is having issue with LG devices    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {        notificationLayoutResID = R.layout.lock_screen_notification_androID_n;    }    RemoteVIEws remoteVIEw = new RemoteVIEws(            context.getPackagename(),notificationLayoutResID);    remoteVIEw.setTextVIEwText(R.ID.Title,Title);    remoteVIEw.setTextVIEwText(R.ID.text,content);    builder.setCustomContentVIEw(remoteVIEw);    Notification notification = builder.build();    publishNotification(context,notification,7);}

然后从lock_screen_notification.xml和lock_screen_notification_androID_n.xml中删除androID:clickable =“true”:

<FrameLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:tools="http://schemas.androID.com/tools"    androID:ID="@+ID/container"    androID:layout_wIDth="match_parent"    androID:layout_height="64dp">    ....
总结

以上是内存溢出为你收集整理的Android锁屏通知自定义视图带波纹和双击全部内容,希望文章能够帮你解决Android锁屏通知自定义视图带波纹和双击所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1132690.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存