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

x33g5p2x  于2022-01-29 转载在 其他  
字(7.6k)|赞(0)|评价(0)|浏览(341)

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

TextView.setBackground介绍

暂无

代码示例

代码示例来源:origin: lygttpod/SuperTextView

/**
 * 设置textView的背景,用户传入drawable实现圆角之类的样式
 *
 * @param textView
 * @param background
 */
private void setDefaultBackground(TextView textView, Drawable background) {
  if (background != null) {
    textView.setVisibility(VISIBLE);
    if (Build.VERSION.SDK_INT < 16) {
      textView.setBackgroundDrawable(background);
    } else {
      textView.setBackground(background);
    }
  }
}

代码示例来源:origin: arcadefire/nice-spinner

@Override
public View getView(int position, @Nullable View convertView, ViewGroup parent) {
  Context context = parent.getContext();
  TextView textView;
  if (convertView == null) {
    convertView = View.inflate(context, R.layout.spinner_list_item, null);
    textView = convertView.findViewById(R.id.text_view_spinner);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
      textView.setBackground(ContextCompat.getDrawable(context, backgroundSelector));
    }
    convertView.setTag(new ViewHolder(textView));
  } else {
    textView = ((ViewHolder) convertView.getTag()).textView;
  }
  textView.setText(spinnerTextFormatter.format(getItem(position).toString()));
  textView.setTextColor(textColor);
  setTextHorizontalAlignment(textView);
  return convertView;
}

代码示例来源:origin: jaydenxiao2016/AndroidFire

/**
 * 设置图片
 *
 * @param drawable
 */
public void setImage(Drawable drawable) {
  if (drawable == null) {
    throw new IllegalArgumentException("drawable cannot be null.");
  }
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    mGood.setBackground(drawable);
  } else {
    mGood.setBackgroundDrawable(drawable);
  }
  mGood.setText("");
  setWidth(drawable.getIntrinsicWidth());
  setHeight(mDistance + drawable.getIntrinsicHeight());
}

代码示例来源:origin: malmstein/yahnac

protected ShowCroutonAction(SnackBarView crouton, CharSequence message) {
  crouton.croutonText.setText(message);
  crouton.croutonText.setBackground(null);
  crouton.croutonUndo.setVisibility(View.GONE);
  crouton.croutonContainer.setBackgroundColor(DEFAULT_BG_COLOR);
  this.crouton = crouton;
  this.animationDuration = DEFAULT_ANIMATION_DURATION_MS;
  this.autohideDelay = DEFAULT_AUTOHIDE_DELAY_MS;
}

代码示例来源:origin: bingoogolapple/BGABanner-Android

if (mNumberIndicatorBackground != null) {
  if (Build.VERSION.SDK_INT >= 16) {
    mNumberIndicatorTv.setBackground(mNumberIndicatorBackground);
  } else {
    mNumberIndicatorTv.setBackgroundDrawable(mNumberIndicatorBackground);

代码示例来源:origin: tz28/Chinese-number-gestures-recognition

public void clearAllFlashTextBackground(int id){
  tv_flashClose.setBackground(null);
  tv_flashOpen.setBackground(null);
  tv_flashKeepOpen.setBackground(null);
  tv_flashAuto.setBackground(null);
  findViewById(id).setBackground(getResources().getDrawable(R.drawable.flash_text_shape));
}

代码示例来源:origin: aurelhubert/ahbottomnavigation

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  Drawable drawable = notificationBackgroundDrawable.getConstantState().newDrawable();
  notification.setBackground(drawable);
} else {
  notification.setBackgroundDrawable(notificationBackgroundDrawable);
Drawable defautlDrawable = ContextCompat.getDrawable(context, R.drawable.notification_background);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
  notification.setBackground(AHHelper.getTintDrawable(defautlDrawable,
      currentBackgroundColor, forceTint));
} else {

代码示例来源:origin: hibernate2011/RosClient

@Override
  public void run() {
    tvLog.setBackground(new BitmapDrawable(getResources(),bitmap));
    tvLog.setText(tvLog.getText() + "Received map,set to background\n");
  }
});

代码示例来源:origin: venshine/GoodView

/**
 * 设置图片
 *
 * @param drawable
 */
public void setImage(Drawable drawable) {
  if (drawable == null) {
    throw new IllegalArgumentException("drawable cannot be null.");
  }
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    mGood.setBackground(drawable);
  } else {
    mGood.setBackgroundDrawable(drawable);
  }
  mGood.setText("");
  setWidth(drawable.getIntrinsicWidth());
  setHeight(mDistance + drawable.getIntrinsicHeight());
}

代码示例来源:origin: gearvrf/GearVRf-Demos

private void addCircleGVRTextViews(GVRApplication application, Resources resources) {
  for (int count = 0; count < NUM_TEXT_VIEWS; count++) {
    TextView textView = new TextView(application.getActivity());
    textView.setLayoutParams(new ViewGroup.LayoutParams(CIRCLE_TEXT_VIEW_WIDTH, CIRCLE_TEXT_VIEW_HEIGHT));
    textView.setTextSize(CIRCLE_TEXT_SIZE);
    textView.setTextColor(Color.BLACK);
    textView.setBackground(resources.getDrawable(R.drawable.circle));
    textView.setGravity(Gravity.CENTER);
    textView.setText(Integer.toString(count + 1));
    circleTextViewList.add(textView);
  }
}

代码示例来源:origin: yaozs/YzsLib

public void setQuantityBackground(Drawable quantityBackground) {
  this.quantityBackground = quantityBackground;
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    mTextViewQuantity.setBackground(quantityBackground);
  } else {
    mTextViewQuantity.setBackgroundDrawable(quantityBackground);
  }
}

代码示例来源:origin: fasteque/rgb-tool

private void setRoundedBackground(TextView textView, int argb) {
    GradientDrawable shape = new GradientDrawable();
    shape.setCornerRadius(360);
    shape.setColor(argb);

    textView.setBackground(shape);
  }
}

代码示例来源:origin: JavaNoober/BackgroundLibrary

tvTest4.setClickable(true);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN){
  tvTest4.setBackground(drawable4);
}else {
  tvTest4.setBackgroundDrawable(drawable4);

代码示例来源:origin: borneywpf/TLRLoadRefresh

@Override
public MainHolder onCreateViewHolder(ViewGroup parent, int viewType) {
  TextView view = (TextView) LayoutInflater.from(parent.getContext()).inflate(android.R.layout.simple_list_item_1, parent, false);
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    view.setBackground(getBackground());
  }
  return new MainHolder(view);
}

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

textView.setBackgroundDrawable(drawable);
} else {
  textView.setBackground(drawable);

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

private void stopAnim(){
  audioLayout.setVisibility(View.GONE);
  mic.setBackground(getResources().getDrawable(R.drawable.mic_bg));
  chronometer.stop();
}

代码示例来源:origin: getActivity/TitleBar

public void setRightBackground(Drawable drawable) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    mRightView.setBackground(drawable);
  }else {
    mRightView.setBackgroundDrawable(drawable);
  }
  post(this);
}

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

private void updateDetailText() {
  //mDetailDoneButton.setText(R.string.quick_settings_done);
  //mDetailSettingsButton.setText(R.string.quick_settings_more_settings);
  int buttonPadding = ResourceUtils.getInstance(mContext).getDimensionPixelSize(R.dimen.qs_detail_button_padding);
  mDetailDoneButton.setBackground(ResourceUtils.getInstance(mContext).getDrawable(R.drawable.qs_btn_borderless_rect));
  mDetailSettingsButton.setBackground(ResourceUtils.getInstance(mContext).getDrawable(R.drawable.qs_btn_borderless_rect));
  mDetailDoneButton.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding);
  mDetailSettingsButton.setPadding(buttonPadding, buttonPadding, buttonPadding, buttonPadding);
}

代码示例来源:origin: getActivity/TitleBar

public void setLeftBackground(Drawable drawable) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
    mLeftView.setBackground(drawable);
  }else {
    mLeftView.setBackgroundDrawable(drawable);
  }
  post(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();
  }
}

相关文章

TextView类方法