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

4

2 回答 2

0

ActionBar您可以使用以下方法在(或)右侧显示应用程序图标Toolbar

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);

对于状态栏,您需要创建自定义布局/覆盖框架代码,检查这个这个答案。

于 2015-10-10T16:52:01.690 回答
0

每个都有不同的 API。见下文:

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

这里这里

或者

作为替代方案,您可以使用自定义通知布局。

于 2015-10-10T17:04:41.873 回答