android.widget.ImageView.setBackground()方法的使用及代码示例

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

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

ImageView.setBackground介绍

暂无

代码示例

代码示例来源:origin: navasmdc/MaterialDesignLibrary

public void setDrawableIcon(Drawable drawableIcon) {
  this.drawableIcon = drawableIcon;
  try {
    icon.setBackground(drawableIcon);
  } catch (NoSuchMethodError e) {
    icon.setBackgroundDrawable(drawableIcon);
  }
}

代码示例来源:origin: scwang90/SmartRefreshLayout

@Override
public void onBindViewHolder(@NonNull ItemViewHolder itemViewHolder, int i) {
  final ItemData data = mDataSet.get(i);
  ShapeDrawable drawable = new ShapeDrawable(new OvalShape());
  drawable.getPaint().setColor(data.color);
  itemViewHolder.icon.setBackground(drawable);
  itemViewHolder.icon.setImageResource(data.icon);
  itemViewHolder.title.setText(data.title);
  itemViewHolder.subTitle.setText(dateFormat.format(data.time));
}

代码示例来源:origin: akexorcist/Android-RoundCornerProgressBar

@SuppressWarnings("deprecation")
private void drawIconBackgroundColor() {
  GradientDrawable iconBackgroundDrawable = createGradientDrawable(colorIconBackground);
  int radius = getRadius() - (getPadding() / 2);
  iconBackgroundDrawable.setCornerRadii(new float[]{radius, radius, 0, 0, 0, 0, radius, radius});
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    ivProgressIcon.setBackground(iconBackgroundDrawable);
  } else {
    ivProgressIcon.setBackgroundDrawable(iconBackgroundDrawable);
  }
}

代码示例来源:origin: mancj/MaterialSearchBar

/**
 * Setup editText coloring and drawables
 */
private void setupSearchEditText() {
  setupCursorColor();
  searchEdit.setHighlightColor(highlightedTextColor);
  if (hintText != null)
    searchEdit.setHint(hintText);
  if (placeholderText != null) {
    arrowIcon.setBackground(null);
    placeHolder.setText(placeholderText);
  }
}

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

public static void setBackground(ImageView imageView, Drawable drawable) {

  // Build.VERSION_CODES.JELLY_BEAN is API LEVEL 16
  if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    imageView.setBackground(drawable);
  } else {
    imageView.setBackgroundDrawable(drawable);
  }
}

代码示例来源:origin: koral--/android-gif-drawable

@SuppressWarnings("deprecation")
static boolean setResource(ImageView view, boolean isSrc, int resId) {
  Resources res = view.getResources();
  if (res != null) {
    try {
      final String resourceTypeName = res.getResourceTypeName(resId);
      if (!SUPPORTED_RESOURCE_TYPE_NAMES.contains(resourceTypeName)) {
        return false;
      }
      GifDrawable d = new GifDrawable(res, resId);
      if (isSrc) {
        view.setImageDrawable(d);
      } else {
        view.setBackground(d);
      }
      return true;
    } catch (IOException | Resources.NotFoundException ignored) {
      //ignored
    }
  }
  return false;
}

代码示例来源:origin: Leaking/WeGit

public static void setIconFont(Context context, ImageView iv, Icon icon,
                int rsid) {
  IconicFontDrawable iconDraw = new IconicFontDrawable(context);
  iconDraw.setIcon(icon);
  iconDraw.setIconColor(context.getResources().getColor(rsid));
  if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN)
    iv.setBackground(iconDraw);
  else
    iv.setBackgroundDrawable(iconDraw);
}

代码示例来源:origin: tommybuonomo/dotsindicator

private ViewGroup buildDot(boolean stroke) {
 ViewGroup dot = (ViewGroup) LayoutInflater.from(getContext()).inflate(R.layout.spring_dot_layout, this, false);
 ImageView dotView = dot.findViewById(R.id.spring_dot);
 dotView.setBackground(
   ContextCompat.getDrawable(getContext(), stroke ? R.drawable.spring_dot_stroke_background : R.drawable.spring_dot_background));
 RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) dotView.getLayoutParams();
 params.width = params.height = stroke ? dotsStrokeSize : dotIndicatorSize;
 params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
 params.setMargins(dotsSpacing, 0, dotsSpacing, 0);
 setUpDotBackground(stroke, dotView);
 return dot;
}

代码示例来源:origin: curtis2/SuperVideoPlayer

@Override
  public void onClick(View v) {
    mCurrentPageSize++;
    if(mCurrentPageSize>3){
      mCurrentPageSize=0;
    }
    T.showToastMsgShort(activity,strDialogs[mCurrentPageSize]);
    mediacontroller_screen_fit.setBackground(getResources().getDrawable(imgs[mCurrentPageSize]));
    activity.setVideoPageSize(mCurrentPageSize);
  }
});

代码示例来源:origin: tommybuonomo/dotsindicator

private void refreshDotsColors() {
 if (dots == null) {
  return;
 }
 for (int i = 0; i < dots.size(); i++) {
  ImageView elevationItem = dots.get(i);
  DotsGradientDrawable background = (DotsGradientDrawable) elevationItem.getBackground();
  if (i == viewPager.getCurrentItem() || (progressMode && i < viewPager.getCurrentItem())) {
   background.setColor(selectedDotColor);
  } else {
   background.setColor(dotsColor);
  }
  elevationItem.setBackground(background);
  elevationItem.invalidate();
 }
}

代码示例来源:origin: pili-engineering/PLDroidShortVideo

@Override
  public View getView(int pos, View convertView, ViewGroup parent) {
    TextView textView;
    ImageView imageView;
    if (convertView == null || mIsNotifyDataChanged) {
      convertView = LayoutInflater.from(mContext).inflate(R.layout.item_draft, parent, false);
      textView = (TextView) convertView.findViewById(R.id.draft_tag);
      textView.setText(mDrafts.get(pos).getTag());
      imageView = (ImageView) convertView.findViewById(R.id.draft_thumbnail);
      PLVideoFrame frame = new PLMediaFile(mDrafts.get(pos).getSectionFilePath(0)).getVideoFrameByTime(100, false);
      if (frame != null){
        imageView.setImageBitmap(frame.toBitmap());
      } else {
        imageView.setBackground(getDrawable(R.drawable.bg_invalid_draft));
      }
    }
    if (pos == mDrafts.size()) {
      mIsNotifyDataChanged = false;
    }
    return convertView;
  }
}

代码示例来源:origin: tommybuonomo/dotsindicator

private void addDots(int count) {
 for (int i = 0; i < count; i++) {
  View dot = LayoutInflater.from(getContext()).inflate(R.layout.dot_layout, this, false);
  ImageView imageView = dot.findViewById(R.id.dot);
  RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) imageView.getLayoutParams();
  params.width = params.height = (int) dotsSize;
  params.setMargins((int) dotsSpacing, 0, (int) dotsSpacing, 0);
  DotsGradientDrawable background = new DotsGradientDrawable();
  background.setCornerRadius(dotsCornerRadius);
  if (isInEditMode()) {
   background.setColor(0 == i ? selectedDotColor : dotsColor);
  } else {
   background.setColor(viewPager.getCurrentItem() == i ? selectedDotColor : dotsColor);
  }
  imageView.setBackground(background);
  final int finalI = i;
  dot.setOnClickListener(new OnClickListener() {
   @Override public void onClick(View v) {
    if (dotsClickable && viewPager != null && viewPager.getAdapter() != null && finalI < viewPager.getAdapter()
      .getCount()) {
     viewPager.setCurrentItem(finalI, true);
    }
   }
  });
  dots.add(imageView);
  addView(dot);
 }
}

代码示例来源:origin: werbhelius/MyCalendarDemo

@Override
  public void destroyItem(ViewGroup container, int position, Object object) {
    container.removeView(mImageList.get(position));
    mImageList.get(position).setBackground(null);
  }
}

代码示例来源:origin: werbhelius/MediaUtils

private void moveAnim(){
    info.setText("松手取消");
    micIcon.setBackground(null);
    micIcon.setBackground(getResources().getDrawable(R.drawable.ic_undo_black_24dp));
  }
}

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

// Create new Instance of imageView
ImageView view = new ImageView(context);
// Get the original view
ImageView org = (ImageView)getChildAt(index);
// Copy drawable of that image
view.setImageDrawable(org.getDrawable());
// Copy Background of that image
view.setBackground(org.getBackground());
// Copy other required properties
....
// Lastly add that view
addView(view);

代码示例来源:origin: enricocid/LaunchEnr

public static void createCircularPreferenceBitmap(Boolean isImage, Preference preference, ImageView imageView, Context context, int color) {
  Bitmap.Config conf = Bitmap.Config.ARGB_8888;
  int dimen = (int) context.getResources().getDimension(android.R.dimen.app_icon_size);
  Bitmap bmp = Bitmap.createBitmap(dimen, dimen, conf);
  if (isImage) {
    imageView.setBackground(createRoundedBitmapDrawable(bmp, color, context.getResources()));
  } else {
    preference.setIcon(createRoundedBitmapDrawable(bmp, color, context.getResources()));
  }
}

代码示例来源:origin: StannyBing/ZXUtils

@Override
public void onBindViewHolder(MainHolder holder, int position) {
  holder.tvToolName.setText(dataList.get(position).getToolName());
  holder.tvClassName.setText(dataList.get(position).getClassName());
  if (dataList.get(position).getResId() != 0) {
    holder.ivImg.setBackground(ContextCompat.getDrawable(context, dataList.get(position).getResId()));
  }
}

代码示例来源:origin: wasdennnoch/AndroidN-ify

private void setupIcon() {
  ImageView im = (ImageView) findViewById(R.id.icon);
  Drawable N = im.getDrawable();
  im.setImageDrawable(null);
  im.setBackground(new RippleDrawable(
      ColorStateList.valueOf(0xFFFFFFFF),
      N,
      null));
  im.setOnClickListener(this);
}

代码示例来源:origin: werbhelius/MediaUtils

private void startAnim(boolean isStart){
  audioLayout.setVisibility(View.VISIBLE);
  info.setText("上滑取消");
  mic.setBackground(getResources().getDrawable(R.drawable.mic_pressed_bg));
  micIcon.setBackground(null);
  micIcon.setBackground(getResources().getDrawable(R.drawable.ic_mic_white_24dp));
  if (isStart){
    chronometer.setBase(SystemClock.elapsedRealtime());
    chronometer.setFormat("%S");
    chronometer.start();
  }
}

代码示例来源:origin: huangfangyi/YiChat

private View getBottomView(final int index,final int page,int drawableRes) {
  View view = getLayoutInflater().inflate(R.layout.layout_big_photo_point, null);
  ImageView button = (ImageView) view.findViewById(R.id.iv_foot_point);
  if (index == page){
    tabs[index].select();
  }
  button.setBackground(getDrawable(drawableRes));
  if (isCompatible(Build.VERSION_CODES.LOLLIPOP)) {
    button.setStateListAnimator(null);
  }
  return view;
}

相关文章

ImageView类方法