0

is it possible to add my app icon to the right side of the status bar (along side the wifi icon, bluetooth icon, etc)? My app start a service in the background so I want do show my app icon when the service is active.

Thank you

Alessandro

AleCat83
  • 1,443
  • 3
  • 22
  • 41

2 Answers2

0

You can show app icon on the right side of ActionBar (or Toolbar) using this:

ActionBar actionBar = getSupportActionBar();
// or Toolbar toolbar = getSupportActionBar();

actionBar.setDisplayOptions(actionBar.getDisplayOptions()
        | ActionBar.DISPLAY_SHOW_CUSTOM);
ImageView imageView = new ImageView(actionBar.getThemedContext());
imageView.setScaleType(ImageView.ScaleType.CENTER);
imageView.setImageResource(R.drawable.your_image);
ActionBar.LayoutParams layoutParams = new ActionBar.LayoutParams(
        ActionBar.LayoutParams.WRAP_CONTENT,
        ActionBar.LayoutParams.WRAP_CONTENT, Gravity.RIGHT
                | Gravity.CENTER_VERTICAL);
imageView.setLayoutParams(layoutParams);
actionBar.setCustomView(imageView);

For status bar, you will need to create your custom layout/override framework code, check this and this answers.

Community
  • 1
  • 1
Ivan V
  • 3,024
  • 4
  • 26
  • 36
0

There are different API's for each. See below:

Notification.Builder nb = new Notification.Builder(context)
.setContentTitle("title")
.setContentText("content")
.setAutoCancel(true)
.setLargeIcon(largeIcon)
.setSmallIcon(R.drawable.small_icon)
.setTicker(s.getText());

see here and here

OR

As an alternative, you could use a custom notification layout.

Milad gh
  • 211
  • 1
  • 11