android.widget.ImageButton.setImageDrawable()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(11.1k)|赞(0)|评价(0)|浏览(199)

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

ImageButton.setImageDrawable介绍

暂无

代码示例

代码示例来源:origin: Manabu-GT/ExpandableTextView

@Override
public void changeState(boolean collapsed) {
  mImageButton.setImageDrawable(collapsed ? mExpandDrawable : mCollapseDrawable);
}

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

private void authenticate() {
 unsub();
 if (RxFingerprint.isAvailable(this)) {
  button.setImageDrawable(on);
  disposable=RxFingerprint.authenticate(this)
   .subscribe(this::onAuthResult,
    t -> {
     Log.e(getClass().getSimpleName(), "Exception authenticating", t);
     button.setImageDrawable(off);
    });
 }
 else {
  Toast.makeText(this, R.string.msg_not_available, Toast.LENGTH_LONG).show();
 }
}

代码示例来源:origin: TangoAgency/material-intro-screen

@SuppressWarnings("PointlessBooleanExpression")
private void nextButtonBehaviour(final int position, final SlideFragment fragment) {
  boolean hasPermissionToGrant = fragment.hasNeededPermissionsToGrant();
  if (hasPermissionToGrant) {
    nextButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_next));
    nextButton.setOnClickListener(permissionNotGrantedClickListener);
  } else if (adapter.isLastSlide(position)) {
    nextButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_finish));
    nextButton.setOnClickListener(finishScreenClickListener);
  } else {
    nextButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.ic_next));
    nextButton.setOnClickListener(new View.OnClickListener() {
      @Override
      public void onClick(View v) {
        if (fragment.canMoveFurther() == false) {
          errorOccurred(fragment);
        } else {
          viewPager.moveToNextPage();
        }
      }
    });
  }
}

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

private void doTheWork() {
 unsub();
 if (RxFingerprint.isAvailable(this)) {
  disposable=RxFingerprint.encrypt(EncryptionMethod.RSA, this, KEY_NAME,
   new String(passphrase))
   .subscribe(this::onEncResult,
    t -> {
     Log.e(getClass().getSimpleName(), "Exception authenticating", t);
     button.setImageDrawable(off);
    });
 }
 else {
  Toast.makeText(this, R.string.msg_not_available, Toast.LENGTH_LONG).show();
 }
}

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

private void onEncResult(FingerprintEncryptionResult encResult) {
 if (encResult.getResult()==FingerprintResult.AUTHENTICATED) {
  button.setImageDrawable(on);
  unsub();
  String encryptedValue=encResult.getEncrypted();
  disposable=RxFingerprint.decrypt(EncryptionMethod.RSA, this, KEY_NAME,
   encryptedValue)
   .subscribe(this::onDecResult,
    t -> {
     Log.e(getClass().getSimpleName(), "Exception decrypting", t);
     button.setImageDrawable(off);
    });
 }
 else {
  Toast.makeText(this, "This was unexpected...", Toast.LENGTH_LONG).show();
 }
}

代码示例来源:origin: xfumihiro/ViewInspector

@SuppressWarnings("deprecation") public void closeToolbar() {
 closeMenu();
 ObjectAnimator animator =
   ObjectAnimator.ofFloat(mToolbar, "translationX", mToolbar.getTranslationX(), mToolbarWidth);
 animator.setInterpolator(new DecelerateInterpolator());
 animator.start();
 mToggleButton.setImageDrawable(
   getResources().getDrawable(R.drawable.ic_chevron_left_white_24dp));
}

代码示例来源:origin: xfumihiro/ViewInspector

@SuppressWarnings("deprecation") public void toggleToolbar() {
 ObjectAnimator animator =
   ObjectAnimator.ofFloat(mToolbar, "translationX", mToolbar.getTranslationX(),
     mToolbar.getTranslationX() < mToolbarClosedWidth ? mToolbarWidth - mToolbarClosedWidth
       : 0);
 animator.setInterpolator(new DecelerateInterpolator());
 animator.start();
 if (mToolbar.getTranslationX() < mToolbarClosedWidth) {
  mToggleButton.setImageDrawable(
    getResources().getDrawable(R.drawable.ic_chevron_left_white_24dp));
 } else {
  mToggleButton.setImageDrawable(
    getResources().getDrawable(R.drawable.ic_chevron_right_white_24dp));
 }
}

代码示例来源:origin: TeamNewPipe/NewPipe

private void toggleExpandRelatedVideos(StreamInfo info) {
  if (DEBUG) Log.d(TAG, "toggleExpandRelatedVideos() called with: info = [" + info + "]");
  if (!showRelatedStreams) return;
  int nextCount = info.getNextVideo() != null ? 2 : 0;
  int initialCount = INITIAL_RELATED_VIDEOS + nextCount;
  if (relatedStreamsView.getChildCount() > initialCount) {
    relatedStreamsView.removeViews(initialCount,
        relatedStreamsView.getChildCount() - (initialCount));
    relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable(
        activity, ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.expand)));
    return;
  }
  //Log.d(TAG, "toggleExpandRelatedVideos() called with: info = [" + info + "], from = [" + INITIAL_RELATED_VIDEOS + "]");
  for (int i = INITIAL_RELATED_VIDEOS; i < info.getRelatedStreams().size(); i++) {
    InfoItem item = info.getRelatedStreams().get(i);
    //Log.d(TAG, "i = " + i);
    relatedStreamsView.addView(infoItemBuilder.buildView(relatedStreamsView, item));
  }
  relatedStreamExpandButton.setImageDrawable(
      ContextCompat.getDrawable(activity,
          ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.collapse)));
}

代码示例来源:origin: ankidroid/Anki-Android

private void setDeckExpander(ImageButton expander, ImageButton indent, Sched.DeckDueTreeNode node){
  boolean collapsed = mCol.getDecks().get(node.did).optBoolean("collapsed", false);
  // Apply the correct expand/collapse drawable
  if (collapsed) {
    expander.setImageDrawable(mExpandImage);
    expander.setContentDescription(expander.getContext().getString(R.string.expand));
  } else if (node.children.size() > 0) {
    expander.setImageDrawable(mCollapseImage);
    expander.setContentDescription(expander.getContext().getString(R.string.collapse));
  } else {
    expander.setImageDrawable(mNoExpander);
  }
  // Add some indenting for each nested level
  int width = (int) indent.getResources().getDimension(R.dimen.keyline_1) * node.depth;
  indent.setMinimumWidth(width);
}

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

private void onAuthResult(FingerprintAuthenticationResult authResult) {
  String msg=getString(R.string.msg_not_possible);

  switch (authResult.getResult()) {
   case FAILED:
    msg=getString(R.string.msg_failed);
    button.setImageDrawable(off);
    unsub();
    break;
   case HELP:
    msg=authResult.getMessage();
    break;
   case AUTHENTICATED:
    msg=getString(R.string.msg_authenticated);
    button.setImageDrawable(off);
    unsub();
    break;
  }

  Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
 }
}

代码示例来源:origin: rockerhieu/emojicon

private void addTabIcon(EmojiconPage page, int index) {
  ImageButton icon = new ImageButton(getContext());
  LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT);
  params.weight = 1;
  icon.setBackground(null);
  icon.setScaleType(ImageView.ScaleType.CENTER);
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
    icon.setImageDrawable(getContext().getResources().getDrawable(page.getIcon()));
  } else {
    icon.setImageDrawable(getContext().getDrawable(page.getIcon()));
  }
  mTabsContainer.addView(icon, mTabsContainer.getChildCount() - 2, params);
  mTabs[index] = icon;
  final int indexToMove = index;
  icon.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View v) {
      mViewPager.setCurrentItem(indexToMove, true);
    }
  });
}

代码示例来源:origin: stackoverflow.com

Drawable originalIcon = ctxt.getResources().getDrawable(iconResId);
Drawable icon = enabled ? originalIcon : convertDrawableToGrayScale(originalIcon);
item.setImageDrawable(icon);

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

private void onDecResult(FingerprintDecryptionResult decResult) {
 String msg=getString(R.string.msg_not_possible);
 switch (decResult.getResult()) {
  case FAILED:
   msg=getString(R.string.msg_failed);
   button.setImageDrawable(off);
   unsub();
   break;
  case HELP:
   msg=decResult.getMessage();
   break;
  case AUTHENTICATED:
   button.setImageDrawable(off);
   unsub();
   if (decResult.getDecrypted().equals(new String(passphrase))) {
    msg=getString(R.string.msg_match);
   }
   else {
    msg=getString(R.string.msg_mismatch);
   }
   break;
 }
 Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
}

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

void revealPostingProgress() {
  Animator reveal = ViewAnimationUtils.createCircularReveal(fabPosting,
      (int) fabPosting.getPivotX(),
      (int) fabPosting.getPivotY(),
      0f,
      fabPosting.getWidth() / 2)
      .setDuration(600L);
  reveal.setInterpolator(AnimUtils.getFastOutLinearInInterpolator(this));
  reveal.start();
  AnimatedVectorDrawable uploading =
      (AnimatedVectorDrawable) getDrawable(R.drawable.avd_uploading);
  if (uploading != null) {
    fabPosting.setImageDrawable(uploading);
    uploading.start();
  }
}

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

(AnimatedVectorDrawable) getDrawable(R.drawable.avd_upload_complete);
if (complete != null) {
  fabPosting.setImageDrawable(complete);
  complete.start();
  fabPosting.postDelayed(() -> fabPosting.setVisibility(View.GONE), 2100); // length of R.drawable.avd_upload_complete
    (AnimatedVectorDrawable) getDrawable(R.drawable.avd_upload_error);
if (failed != null) {
  fabPosting.setImageDrawable(failed);
  failed.start();

代码示例来源:origin: mikepenz/MaterialDrawer

@Override
public void bindView(ViewHolder viewHolder, List payloads) {
  super.bindView(viewHolder, payloads);
  Context ctx = viewHolder.itemView.getContext();
  //bind the basic view parts
  bindViewHelper(viewHolder);
  //handle menu click
  viewHolder.menu.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
      PopupMenu popup = new PopupMenu(view.getContext(), view);
      MenuInflater inflater = popup.getMenuInflater();
      inflater.inflate(mMenu, popup.getMenu());
      popup.setOnMenuItemClickListener(mOnMenuItemClickListener);
      popup.setOnDismissListener(mOnDismissListener);
      popup.show();
    }
  });
  //handle image
  viewHolder.menu.setImageDrawable(new IconicsDrawable(ctx, GoogleMaterial.Icon.gmd_more_vert).sizeDp(12).color(getIconColor(ctx)));
  //call the onPostBindView method to trigger post bind view actions (like the listener to modify the item if required)
  onPostBindView(this, viewHolder.itemView);
}

代码示例来源:origin: TeamNewPipe/NewPipe

relatedStreamExpandButton.setVisibility(View.VISIBLE);
  relatedStreamExpandButton.setImageDrawable(ContextCompat.getDrawable(
      activity, ThemeHelper.resolveResourceIdFromAttr(activity, R.attr.expand)));
} else {

代码示例来源:origin: pchmn/MaterialChipsInput

mDeleteButton.setImageDrawable(mDeleteIcon);
if(mDeleteIconColor != null)
  mDeleteButton.getDrawable().mutate().setColorFilter(mDeleteIconColor.getDefaultColor(), PorterDuff.Mode.SRC_ATOP);

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

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 off=DrawableCompat.wrap(VectorDrawableCompat.create(getResources(),
  R.drawable.ic_fingerprint_black_24dp, null));
 off.setTint(getResources().getColor(android.R.color.black, null));
 on=DrawableCompat.wrap(VectorDrawableCompat.create(getResources(),
  R.drawable.ic_fingerprint_black_24dp, null));
 on.setTint(getResources().getColor(R.color.primary, null));
 button=findViewById(R.id.fingerprint);
 button.setImageDrawable(off);
 button.setOnClickListener(view -> authenticate());
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 off=DrawableCompat.wrap(VectorDrawableCompat.create(getResources(),
  R.drawable.ic_fingerprint_black_24dp, null));
 off.setTint(getResources().getColor(android.R.color.black, null));
 on=DrawableCompat.wrap(VectorDrawableCompat.create(getResources(),
  R.drawable.ic_fingerprint_black_24dp, null));
 on.setTint(getResources().getColor(R.color.primary, null));
 button=findViewById(R.id.fingerprint);
 button.setImageDrawable(off);
 button.setOnClickListener(view -> doTheWork());
}

相关文章

ImageButton类方法