Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

172
Vistas
establecer diferentes colores para las acciones de notificación

Hola, estoy configurando una notificación para llamadas entrantes con dos acciones: Responder y Rechazar. Necesito configurar el color verde para la acción de Respuesta y el rojo para Rechazar. Pero no pude encontrar una solución.

Aquí está mi código:

 NotificationCompat.Builder builder = new NotificationCompat.Builder(mContext,"Call") .setSmallIcon(R.drawable.ic_stat_rider_logo) .setContentIntent(contentIntent) .setContentTitle(generalFunc.retrieveLangLBl("","LBL_SINCH_NOTIFICATION_CONTENT")) .setContentText(call.getHeaders().get("Name") +" "+ generalFunc.retrieveLangLBl("","LBL_SINCH_NOTIFICATION_TITLE")); builder.addAction(getServiceNotificationAction(mContext, denyCallIntent(mContext,call),R.drawable.ic_call_icon, R.string.decline)); builder.addAction(getServiceNotificationAction(mContext, answerCallIntent(mContext,call),R.drawable.com_facebook_close, R.string.answer)); if (callActivityRestricted()) { builder.setFullScreenIntent(contentIntent, true); builder.setPriority(NotificationCompat.PRIORITY_HIGH); builder.setCategory(NotificationCompat.CATEGORY_CALL); } private NotificationCompat.Action getServiceNotificationAction(Context context, Intent intent, int iconResId, int titleResId) { PendingIntent pendingIntent = Build.VERSION.SDK_INT >= 26 ? PendingIntent.getForegroundService(context, 0, intent, 0) : PendingIntent.getService(context, 0, intent, 0); return new NotificationCompat.Action(iconResId, context.getString(titleResId), pendingIntent); }

Probé setColor() , pero establece un color único para ambas acciones.

Por favor ayúdame a solucionar esto . gracias de antemano

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Probé tu código y lo logré con la ayuda de la clase Spannable.

 public void sendOnChannel1(View v) { String title = editTextTitle.getText().toString(); String message = editTextMessage.getText().toString(); Intent activityIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, activityIntent, 0); Intent broadcastIntent = new Intent(this, NotificationReceiver.class); broadcastIntent.putExtra("toastMessage", message); PendingIntent actionIntent = PendingIntent.getBroadcast(this, 0, broadcastIntent, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new NotificationCompat.Builder(this, App.CHANNEL_1_ID) .setSmallIcon(R.drawable.ic_launcher_background) .setContentTitle(title) .setContentText(message) .setPriority(NotificationCompat.PRIORITY_HIGH) .setCategory(NotificationCompat.CATEGORY_MESSAGE) .setContentIntent(contentIntent) .setAutoCancel(true) .setColorized(true) .setOnlyAlertOnce(true) .setPriority(NotificationCompat.PRIORITY_HIGH) .addAction(R.mipmap.ic_launcher, getMyActionText(R.string.answer,R.color.green), actionIntent) .addAction(R.mipmap.ic_launcher, getMyActionText(R.string.decline,R.color.red), actionIntent) .build(); notificationManager.notify(1, notification); }

ingrese la descripción de la imagen aquí

Aquí hay un método de ayuda que utilicé:

 private Spannable getMyActionText(@StringRes int stringRes, @ColorRes int colorRes) { Spannable spannable = new SpannableString(this.getText(stringRes)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) { spannable.setSpan( new ForegroundColorSpan(this.getColor(colorRes)), 0, spannable.length(), 0); } return spannable; }
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda