Passage of parameter Drawable object

Asked

Viewed 61 times

0

I created a method to encapsulate a notification message (Notification.Builder). An excerpt from the code is shown below:

 public void exibirMensagem(String titulo, String texto,Drawable icone)
{
    Notification.Builder mensagem = new Notification.Builder(contexto)
             //TROCAR PARA O ÍCONE PADRÃO DA APLICACAO
            .setSmallIcon(icone);}

It turns out that the method .setSmallIcone does not accept the icon object that was passed by parameter. icone is underlined in vermellho and when I step the mouse course appears the following message:

Cannot resolved method 'setSmallIcon(android.graphics.drawable.Drawable

How can I solve this, ie pass a Drawable as parameter and use in the method setSmallIcon?

  • You must pass int of the icon by parameter. Example: exibirMensagem(String titulo, String texto,int icone). You do it this way: exibirMensagem("Titulo", "Conteudo",R.drawable.meu_icone)

1 answer

3


According to the documentation, the parameter that must be passed to setSmallICon is a Int instead of a Drawable.

So your code should be like this:

public void exibirMensagem(String titulo, String texto, int icone)
{
    Notification.Builder mensagem = new Notification.Builder(contexto)
         //TROCAR PARA O ÍCONE PADRÃO DA APLICACAO
        .setSmallIcon(icone);
}

How to use the above code?

// FloatingActionButton -> OnClickListener...
exibirMensagem("hello world", "Hello world is so nice, guys!", R.drawable.ic_hello_app);
  • 1

    That’s exactly what I said. huehueBr

  • I didn’t copy your answer, let alone see your comment. I just posted mine. I opened the documentation and saw the parameters that the function asks and showed the user the path. Before you think I’m copying your answers, take a look at yours. Almost all are based on answers to other questions, most are pure copying. Abç.

  • 1

    I didn’t say you were wrong, I said that’s exactly what I said. I’ll even give you a +1 for being a valid answer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.