AndroidAuto:自定义操作的图标未显示
创始人
2024-10-06 10:02:04
0
  1. 确保图标资源文件被正确命名并放置在drawable文件夹下。
  2. 使用 NotificationCompat.BuildersetAutoAction() 方法设置操作项时,确保将正确的资源ID传递给 setCustomAction() 方法的第二个参数。 例如:
NotificationCompat.Action customAction = new NotificationCompat.Action.Builder(
            R.drawable.ic_custom_action, "Custom Action",
            customActionPendingIntent).build();

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle("My Notification Title")
            .setContentText("This is my notification content.")
            .setAutoAction(customAction);
  1. 如果您是使用 RemoteViews 创建自定义通知布局,请确保使用 setImageViewResource() 方法将正确的图标资源 ID 分配给操作项图标视图。例如:
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.my_custom_notification);
remoteViews.setImageViewResource(R.id.custom_action_icon, R.drawable.ic_custom_action);

// Set custom action
Intent customActionIntent = new Intent(this, MyBroadcastReceiver.class);
customActionIntent.setAction("com.example.CUSTOM_ACTION");
PendingIntent customActionPendingIntent = PendingIntent.getBroadcast(this, 0, customActionIntent, PendingIntent.FLAG_UPDATE_CURRENT);

remoteViews.setOnClickPendingIntent(R.id.custom_action_button, customActionPendingIntent);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, CHANNEL_ID)
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle("My Notification Title")
            .setContentText("This is my notification content.")
            .setCustomContentView(remoteViews);

相关内容

热门资讯

此事迅速冲上热搜!智星德州插件... 此事迅速冲上热搜!智星德州插件2024最新版,蜀渝牌乐汇修改器,本来真的是有挂(详细必赢教程)-哔哩...
透视科技!哈糖大菠萝助手(透视... 透视科技!哈糖大菠萝助手(透视)开挂辅助方法(总是真的是有挂)-哔哩哔哩透视科技!哈糖大菠萝助手(透...
透视教学!来玩app 德州 辅... 透视教学!来玩app 德州 辅助,约局吧如何查看是否有挂,指南书教程(都是真的有挂)-哔哩哔哩1、操...
据文件显示!aapoker怎么... 据文件显示!aapoker怎么控制牌,博雅棋牌辅助器,好像真的是有挂(分享总结教程)-哔哩哔哩1、起...
透视神器!pokemmo脚本(... 透视神器!pokemmo脚本(透视)开挂辅助神器(原来是真的挂)-哔哩哔哩1、用户打开应用后不用登录...
透视透视!aapoker怎么控... 透视透视!aapoker怎么控制牌,wepoker怎么设置房间,办法教程(竟然是真的挂)-哔哩哔哩1...
透视软件!pokemmo手机版... 透视软件!pokemmo手机版脚本免费,麻雀智能辅助软件,总是存在有挂(揭露2025新版)-哔哩哔哩...
透视苹果版本!wepoker透... 透视苹果版本!wepoker透视脚本免费使用视频(透视)开挂辅助软件(其实是真的挂)-哔哩哔哩1、w...
透视app!hhpoker有透... 透视app!hhpoker有透视功能吗,哈糖大菠萝有挂吗,手段教程(一贯真的是有挂)-哔哩哔哩hhp...
透视工具!htx矩阵wepok... 透视工具!htx矩阵wepoker辅助,兴动互娱辅助工具,真是存在有挂(教你2025新版教程)-哔哩...