【问题标题】:add app icon to the right side of the status bar在状态栏右侧添加应用图标
【发布时间】:2015-10-10 16:19:36
【问题描述】:

是否可以将我的应用程序图标添加到状态栏的右侧(在 wifi 图标、蓝牙图标等旁边)? 我的应用在后台启动服务,因此我想在服务处于活动状态时显示我的应用图标。

谢谢

亚历山德罗

【问题讨论】:

标签: android android-icons android-statusbar


【解决方案1】:

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

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

见here和here

或

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

【讨论】:

    【解决方案2】:

    您可以使用以下方法在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);
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-08-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-23
      • 2011-04-25
      • 2020-02-03
      • 2023-03-13
      相关资源
      最近更新 更多