android.graphics.drawable.Icon.createWithResource()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(8.5k)|赞(0)|评价(0)|浏览(300)

本文整理了Java中android.graphics.drawable.Icon.createWithResource()方法的一些代码示例,展示了Icon.createWithResource()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Icon.createWithResource()方法的具体详情如下:
包路径:android.graphics.drawable.Icon
类名称:Icon
方法名:createWithResource

Icon.createWithResource介绍

暂无

代码示例

代码示例来源:origin: commonsguy/cw-omnibus

private Icon buildIcon(Bookmark item) {
  return(Icon.createWithResource(getActivity(),
   R.drawable.ic_bookmark_border_black_24dp));
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

private ChooserTarget buildTarget(int targetId) {
  String title=String.format(titleTemplate, targetId);
  int iconId=getResources().getIdentifier("ic_share" + targetId,
    "drawable", getPackageName());
  Icon icon=Icon.createWithResource(this, iconId);
  float score=1.0f-((float)targetId/40);
  ComponentName cn=new ComponentName(this, FauxSender.class);
  Bundle extras=new Bundle();

  extras.putInt(FauxSender.EXTRA_TARGET_ID, targetId);

  return(new ChooserTarget(title, icon, score, cn, extras));
 }
}

代码示例来源:origin: commonsguy/cw-omnibus

private RemoteAction buildRemoteAction(int requestCode, int iconId,
                     int titleId, int descId) {
  Intent i=new Intent(this, RemoteActionReceiver.class)
   .putExtra(EXTRA_REQUEST, requestCode);
  PendingIntent pi=PendingIntent.getBroadcast(this, requestCode, i, 0);
  Icon icon=Icon.createWithResource(this, iconId);
  String title=getString(titleId);
  String desc=getString(descId);

  return(new RemoteAction(icon, title, desc, pi));
 }
}

代码示例来源:origin: nickbutcher/plaid

@TargetApi(Build.VERSION_CODES.N_MR1)
public static void enablePostShortcut(@NonNull Context context) {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
  ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
  Intent intent = ActivityHelper.intentTo(Activities.DesignerNews.PostStory.INSTANCE);
  intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
  ShortcutInfo postShortcut
      = new ShortcutInfo.Builder(context, POST_SHORTCUT_ID)
      .setShortLabel(context.getString(R.string.shortcut_post_short_label))
      .setLongLabel(context.getString(R.string.shortcut_post_long_label))
      .setDisabledMessage(context.getString(R.string.shortcut_post_disabled))
      .setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_post))
      .setIntent(intent)
      .build();
  shortcutManager.addDynamicShortcuts(Collections.singletonList(postShortcut));
}

代码示例来源:origin: commonsguy/cw-omnibus

private void updateTile() {
 Tile tile=getQsTile();
 if (tile!=null) {
  boolean isEnabled=getPrefs().getBoolean(MonitorApp.PREF_ENABLED, false);
  int state=isEnabled ? Tile.STATE_ACTIVE : Tile.STATE_INACTIVE;
  tile.setIcon(Icon.createWithResource(this,
   R.drawable.ic_new_releases_24dp));
  tile.setLabel(getString(R.string.app_name));
  tile.setState(state);
  tile.updateTile();
 }
}

代码示例来源:origin: android-hacker/VirtualXposed

(Build.BRAND.equalsIgnoreCase("samsung") || Build.MANUFACTURER.equalsIgnoreCase("samsung"))) {
notification.icon = getHostContext().getApplicationInfo().icon;
Icon icon = Icon.createWithResource(getHostPkg(), notification.icon);
Reflect.on(notification).call("setSmallIcon", icon);

代码示例来源:origin: robolectric/robolectric

@Test
public void testGetRes() {
 Icon icon =
   Icon.createWithResource(
     ApplicationProvider.getApplicationContext(), android.R.drawable.ic_delete);
 assertThat(shadowOf(icon).getType()).isEqualTo(TYPE_RESOURCE);
 assertThat(shadowOf(icon).getResId()).isEqualTo(android.R.drawable.ic_delete);
}

代码示例来源:origin: iTXTech/Daedalus

public static void updateShortcut(Context context) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
    Log.d("Daedalus", "Updating shortcut");
    boolean activate = DaedalusVpnService.isActivated();
    String notice = activate ? context.getString(R.string.button_text_deactivate) : context.getString(R.string.button_text_activate);
    ShortcutInfo info = new ShortcutInfo.Builder(context, Daedalus.SHORTCUT_ID_ACTIVATE)
        .setLongLabel(notice)
        .setShortLabel(notice)
        .setIcon(Icon.createWithResource(context, R.mipmap.ic_launcher))
        .setIntent(new Intent(context, MainActivity.class).setAction(Intent.ACTION_VIEW)
            .putExtra(MainActivity.LAUNCH_ACTION, activate ? MainActivity.LAUNCH_ACTION_DEACTIVATE : MainActivity.LAUNCH_ACTION_ACTIVATE))
        .build();
    ShortcutManager shortcutManager = (ShortcutManager) context.getSystemService(SHORTCUT_SERVICE);
    shortcutManager.addDynamicShortcuts(Collections.singletonList(info));
  }
}

代码示例来源:origin: googlesamples/android-PictureInPicture

new Intent(ACTION_MEDIA_CONTROL).putExtra(EXTRA_CONTROL_TYPE, controlType),
        0);
final Icon icon = Icon.createWithResource(MainActivity.this, iconId);
actions.add(new RemoteAction(icon, title, title, intent));
        Icon.createWithResource(MainActivity.this, R.drawable.ic_info_24dp),
        getString(R.string.info),
        getString(R.string.info_description),

代码示例来源:origin: ukanth/afwall

public void cbFunc(RootCommand state) {
    Api.setEnabled(context, state.exitCode != 0, true);
    tile.setState(Tile.STATE_INACTIVE);// e() method form java, used in Kotlin as a property
    tile.setLabel(getString(R.string.inactive));
    tile.setIcon(Icon.createWithResource(context, R.drawable.notification_error));
    tile.updateTile();
  }
}));

代码示例来源:origin: ukanth/afwall

public void cbFunc(RootCommand state) {
    // setEnabled always sends us a STATUS_CHANGED_MSG intent to update the icon
    Api.setEnabled(context, state.exitCode == 0, true);
    tile.setState(Tile.STATE_ACTIVE);
    tile.setLabel(getString(R.string.active));
    tile.setIcon(Icon.createWithResource(context, R.drawable.notification));
    tile.updateTile();
  }
}));

代码示例来源:origin: ukanth/afwall

@Override
public void onStartListening() {
  super.onStartListening();
  boolean status = Api.isEnabled(this);
  Tile tile = getQsTile(); // this is getQsTile() method form java, used in Kotlin as a property
  if (tile != null) {
    if (!status) {
      tile.setLabel(getString(R.string.inactive));
      tile.setIcon(Icon.createWithResource(this, R.drawable.notification_error));
      tile.setState(Tile.STATE_INACTIVE);
    } else {
      tile.setLabel(getString(R.string.active));
      tile.setIcon(Icon.createWithResource(this, R.drawable.notification));
      tile.setState(Tile.STATE_ACTIVE);
    }
    tile.updateTile();
  }
}

代码示例来源:origin: r3bl-org/stay-awake-app

@Override
public void onCreate() {
  super.onCreate();
  mHandler = new Handler();
  mIconEyeOpen = Icon.createWithResource(this, R.drawable.ic_stat_visibility);
  mIconEyeClosed = Icon.createWithResource(this, R.drawable.ic_stat_visibility_off);
  d(TAG, "onCreate: ");
}

代码示例来源:origin: Kr328/nevo-decorators-sms-captchas

protected Notification.Action createNonIconAction(String key, String title, Parcelable cookies) {
  Icon icon = Icon.createWithResource(this, R.drawable.ic_empty);
  Intent intent = new Intent().setAction(INTENT_ACTION_CLICKED_ACTION).putExtra(INTENT_EXTRA_COOKIES, cookies).putExtra(INTENT_EXTRA_NOTIFICATION_KEY, key);
  PendingIntent pendingIntent = PendingIntent.getBroadcast(this, cookies.hashCode(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
  return new Notification.Action.Builder(icon, title, pendingIntent).build();
}

代码示例来源:origin: commonsguy/cw-androidarch

@TargetApi(Build.VERSION_CODES.O)
 private RemoteAction buildRemoteAction(int requestCode, int iconId,
                     int titleId, int descId) {
  Intent i=new Intent(this, RemoteActionReceiver.class)
   .putExtra(EXTRA_REQUEST, requestCode);
  PendingIntent pi=PendingIntent.getBroadcast(this, requestCode, i, 0);
  Icon icon=Icon.createWithResource(this, iconId);
  String title=getString(titleId);
  String desc=getString(descId);

  return(new RemoteAction(icon, title, desc, pi));
 }
}

代码示例来源:origin: fython/Blackbulb

private void updateActiveTile(Tile tile) {
  Icon activeIcon = Icon
      .createWithResource(getApplicationContext(),
          R.drawable.ic_qs_night_mode_on);
  tile.setIcon(activeIcon);
  tile.setState(Tile.STATE_ACTIVE);
  tile.updateTile();
}

代码示例来源:origin: fennifith/Status

@Override
public void onTileAdded() {
  super.onTileAdded();
  Tile tile = getQsTile();
  if (tile != null) {
    tile.setIcon(Icon.createWithResource(this, StaticUtils.isStatusServiceRunning(this) ? R.drawable.ic_check_box_enabled : R.drawable.ic_check_box_disabled));
    tile.updateTile();
  }
}

代码示例来源:origin: fennifith/Status

@Override
public void onStartListening() {
  super.onStartListening();
  Tile tile = getQsTile();
  if (tile != null) {
    tile.setIcon(Icon.createWithResource(this, StaticUtils.isStatusServiceRunning(this) ? R.drawable.ic_check_box_enabled : R.drawable.ic_check_box_disabled));
    tile.updateTile();
  }
}

代码示例来源:origin: Omico/CurrentActivity

@Override
public void onStartListening() {
  super.onStartListening();
  tile = getQsTile();
  icon = Icon.createWithResource(getApplicationContext(), R.mipmap.ic_launcher);
  if (ServiceUtils.isRunning(getApplicationContext(), FloatViewService.class.getName())) {
    setEnableTile();
  } else {
    setDisableTile();
  }
  tile.updateTile();
}

代码示例来源:origin: haruue/WADB

private void showStateOn(String ip, int port) {
  Tile tile = getQsTile();
  tile.setState(Tile.STATE_ACTIVE);
  tile.setIcon(Icon.createWithResource(getApplication(), R.drawable.ic_qs_network_adb_on));
  tile.setLabel(ip + ":" + port);
  tile.updateTile();
}

相关文章