【问题标题】:How to generate icon programmatically and use it instead of a shortcut icon?如何以编程方式生成图标并使用它而不是快捷方式图标?
【发布时间】:2019-08-24 11:58:13
【问题描述】:

有没有办法以编程方式生成图标(恒定背景,中心文本(来自可以更改的变量))并使用它来代替快捷方式图标?

【问题讨论】:

  • 这只能通过自定义启动器来实现。应用程序无法更改其图标而不进行升级。
  • @JakeB,我说的是快捷方式图标,而不是应用程序图标。要将图标放入快捷方式,我使用 Intent extra:intent.putExtra("android.intent.extra.shortcut.ICON_RESOURCE", Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.icon));我可以通过编程方式生成它......但不知道如何。

标签: java android icons android-drawable shortcut


【解决方案1】:

看起来 Android 的 ShortcutManager 可能最适合您的需求,因为它允许静态和动态生成快捷方式。 https://developer.android.com/guide/topics/ui/shortcuts.html#dynamic

ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

ShortcutInfo shortcut = new ShortcutInfo.Builder(this, SHORTCUT_ID)
    .setShortLabel("My Shortcut")
    .setLongLabel("This is my shortcut")
    .setIcon(Icon.createWithResource(context, R.drawable.mipmap))
    .setIntent(SHORTCUT_ACTION)
    .build();

shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 2013-06-08
    • 2012-08-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-08
    相关资源
    最近更新 更多