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
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
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.
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());
OR
As an alternative, you could use a custom notification layout.