Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

179
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda