AleCat83
AleCat83

Reputation: 1493

change notification addAction icon and text color without using custom layouts

In my application I have a notification always active. I add an action to perform some operations when the user click on the action icon. I used a colored icon for the action but when the notification gets displayed it is always gray. Is there a way to color the icon? Also, the action title is always in uppercase, is it possible to use a lowercase text and maybe change the text color too?

EDIT: I prefer not using a custom layout for better compatibility

NotificationCompat.Builder builder = new NotificationCompat.Builder(ctx);
builder.setSmallIcon(R.drawable.ic_stat_logo);
builder.setContentTitle("my title");
builder.setContentText("my content");

Intent myIntent = new Intent();
myIntent.putExtra("id", variable.id);
            myIntent.setAction(NotificationsReceiver.ACTION);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(ctx, 1, myIntent, PendingIntent.FLAG_CANCEL_CURRENT);

            NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.action_icon_green,
                    ctx.getResources().getString(R.string.action_title),
                    pendingIntent).build();

            builder.addAction(action);

Upvotes: 4

Views: 3751

Answers (1)

Amol Suryawanshi
Amol Suryawanshi

Reputation: 2184

you can use this code to change notification action color

NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder.setColor(context.getResources().getColor(R.color.colorPrimary));

Upvotes: 1

Related Questions