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

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

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

TextView.setBackgroundColor介绍

暂无

代码示例

代码示例来源:origin: liaoinstan/SpringView

@Override
public void onBindViewHolder(final SampleViewHolder holder, final int position) {
  holder.text_item.setText(results.get(position));
  if ((position+1)/2 % 2 == 1) {
    holder.text_item.setBackgroundColor(Color.parseColor("#e3f1fc"));
    holder.text_item.setTextColor(Color.parseColor("#9dd2fc"));
  } else {
    holder.text_item.setBackgroundColor(Color.parseColor("#ffffff"));
    holder.text_item.setTextColor(Color.parseColor("#cccccc"));
  }
}

代码示例来源:origin: alibaba/Tangram-Android

@Override
public void bindView(@NonNull TextView view) {
  TextView textView = view;
  textView.setText(
      id + " pos: " + pos + " " + parent.getClass().getSimpleName() + " " + optParam(
          "msg"));
  if (pos > 57) {
    textView.setBackgroundColor(0x66cccf00 + (pos - 50) * 128);
  } else if (pos % 2 == 0) {
    textView.setBackgroundColor(0xaaaaff55);
  } else {
    textView.setBackgroundColor(0xccfafafa);
  }
}

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

// Creating the AlertDialog with a custom xml layout (you can still use the default Android version)
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = (LayoutInflater)this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.viewname, null);
builder.setView(view);

TextView title = new TextView(this);
// You Can Customise your Title here 
title.setText("Custom Centered Title");
title.setBackgroundColor(Color.DKGRAY);
title.setPadding(10, 10, 10, 10);
title.setGravity(Gravity.CENTER);
title.setTextColor(Color.WHITE);
title.setTextSize(20);

builder.setCustomTitle(title);

代码示例来源:origin: tyzlmjj/PagerBottomTabStrip

@Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    String content = getArguments().getString(ARG_C);
    TextView textView = new TextView(getContext());
    textView.setTextSize(30);
    textView.setGravity(Gravity.CENTER);
    textView.setText(String.format("Test\n\n%s", content));
    textView.setBackgroundColor(0xFFececec);
    return textView;
  }
}

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

twoByTwo1.setLayoutParams(first);
twoByTwo1.setGravity(Gravity.CENTER);
twoByTwo1.setBackgroundColor(Color.RED);
twoByTwo1.setText("TOP");
twoByTwo1.setTextAppearance(this, android.R.style.TextAppearance_Large);
gridLayout.addView(twoByTwo1, first);
second.height = quarterScreenWidth;
twoByOne1.setLayoutParams(second);
twoByOne1.setBackgroundColor(Color.BLUE);
twoByOne1.setText("Staff Choices");
twoByOne1.setTextAppearance(this, android.R.style.TextAppearance_Large);
gridLayout.addView(twoByOne1, second);
third.height = quarterScreenWidth;
twoByOne2.setLayoutParams(third);
twoByOne2.setBackgroundColor(Color.GREEN);
twoByOne2.setText("Games");
twoByOne2.setTextAppearance(this, android.R.style.TextAppearance_Large);
gridLayout.addView(twoByOne2, third);
fourth.height = quarterScreenWidth;
twoByOne3.setLayoutParams(fourth);
twoByOne3.setBackgroundColor(Color.YELLOW);
fifth.height = quarterScreenWidth;
twoByOne4.setLayoutParams(fifth);
twoByOne4.setBackgroundColor(Color.MAGENTA);

代码示例来源:origin: sockeqwe/AdapterDelegates

@Override
protected void onBindViewHolder(@NonNull Item item, @NonNull ItemViewHolder holder,
                @NonNull List<Object> payloads) {
  Log.d("ItemAdapterDelegate", "Change Payload: " + payloads);
  holder.textView.setText(item.text);
  holder.textView.setBackgroundColor(item.color);
}

代码示例来源:origin: liaoinstan/SpringView

@Override
public void onBindViewHolder(final RecyclerViewAdapter.SampleViewHolder holder, final int position) {
  holder.text_item.setText(results.get(position));
  if (position % 2 == 1) {
    holder.text_item.setBackgroundColor(Color.parseColor("#ffffff"));
    holder.text_item.setTextColor(Color.parseColor("#cccccc"));
  } else {
    holder.text_item.setBackgroundColor(Color.parseColor("#bce1d8"));
    holder.text_item.setTextColor(Color.parseColor("#ffffff"));
  }
}

代码示例来源:origin: JessYanCoding/AndroidAutoSize

public static View createTextView(LayoutInflater inflater, String content, int backgroundColor) {
    TextView view = new TextView(inflater.getContext());
    ViewGroup.LayoutParams layoutParams =
        new ViewGroup.LayoutParams((AutoSizeUtils.dp2px(inflater.getContext(), 360)),
            ViewGroup.LayoutParams.MATCH_PARENT);
    view.setLayoutParams(layoutParams);
    view.setText(content);
    view.setTextColor(0xffffffff);
    view.setGravity(Gravity.CENTER);
    view.setTextSize(30);
    view.setBackgroundColor(backgroundColor);
    return view;
  }
}

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

@Override
protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.dynamic_linearlayout);

  LinearLayout linearLayout = (LinearLayout) findViewById(R.id.ll_example);

  // Add textview 1
  TextView textView1 = new TextView(this);
  textView1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
      LayoutParams.WRAP_CONTENT));
  textView1.setText("programmatically created TextView1");
  textView1.setBackgroundColor(0xff66ff66); // hex color 0xAARRGGBB
  textView1.setPadding(20, 20, 20, 20);// in pixels (left, top, right, bottom)
  linearLayout.addView(textView1);

  // Add textview 2
  TextView textView2 = new TextView(this);
  LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
      LayoutParams.WRAP_CONTENT);
  layoutParams.gravity = Gravity.RIGHT;
  layoutParams.setMargins(10, 10, 10, 10); // (left, top, right, bottom)
  textView2.setLayoutParams(layoutParams);
  textView2.setText("programmatically created TextView2");
  textView2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
  textView2.setBackgroundColor(0xffffdbdb); // hex color 0xAARRGGBB
  linearLayout.addView(textView2);
}

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

private void populateTextView(TextView tv, int position) {
  int blue=position * 25;
  tv.setText(String.format(getString(R.string.item), position + 1));
  tv.setBackgroundColor(Color.argb(255, 0, 0, blue));
 }
}

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

private void previewLayout(Context context) {
  setGravity(Gravity.CENTER);
  TextView tv = new TextView(context);
  ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
  tv.setLayoutParams(params);
  tv.setGravity(Gravity.CENTER);
  tv.setText(getClass().getSimpleName());
  tv.setTextColor(Color.WHITE);
  tv.setBackgroundColor(Color.GRAY);
  addView(tv);
}

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

TextView tv = new TextView(this);
tv.setLayoutParams(new ViewGroup.LayoutParams(
    ViewGroup.LayoutParams.WRAP_CONTENT,
    ViewGroup.LayoutParams.WRAP_CONTENT));

llview.addView(tv);
tv.setTextColor(Color.WHITE);
tv.setTextSize(2,25);
tv.setText(chat);
if (mine) {
  leftMargin = 5;
  tv.setBackgroundColor(0x7C5B77);
}
else {
  leftMargin = 50;
  tv.setBackgroundColor(0x778F6E);
}
final ViewGroup.MarginLayoutParams lpt =(MarginLayoutParams)tv.getLayoutParams();
lpt.setMargins(leftMargin,lpt.topMargin,lpt.rightMargin,lpt.bottomMargin);

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

textView1.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,
    LayoutParams.WRAP_CONTENT));
textView1.setText("programmatically created TextView1");
textView1.setBackgroundColor(0xff66ff66); // hex color 0xAARRGGBB
textView1.setPadding(20, 20, 20, 20); // in pixels (left, top, right, bottom)
linearLayout.addView(textView1);
layoutParams.setMargins(10, 10, 10, 10); // (left, top, right, bottom)
textView2.setLayoutParams(layoutParams);
textView2.setText("programmatically created TextView2");
textView2.setTextSize(TypedValue.COMPLEX_UNIT_SP, 18);
textView2.setBackgroundColor(0xffffdbdb); // hex color 0xAARRGGBB
linearLayout.addView(textView2);

代码示例来源:origin: alibaba/Tangram-Android

@Override
public void postBindView(BaseCell cell) {
  int pos = cell.pos;
  String parent = "";
  if (cell.parent != null) {
    parent = cell.parent.getClass().getSimpleName();
  }
  textView.setText(
      cell.id + " pos: " + pos + " " + parent + " " + cell
          .extras.get("msg"));
  if (pos > 57) {
    textView.setBackgroundColor(0x66cccf00 + (pos - 50) * 128);
  } else if (pos % 2 == 0) {
    textView.setBackgroundColor(0xaaaaff55);
  } else {
    textView.setBackgroundColor(0xcceeeeee);
  }
}

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

TextView textview = new TextView(context);
   textview.setText(text);
   textview.setBackgroundColor(Color.GRAY);
   textview.setTextColor(Color.BLUE);
   textview.setPadding(10,10,10,10);
   Toast toast = new Toast(context);
   toast.setView(textview);
   toast.setDuration(Toast.LENGTH_LONG);
   toast.setGravity(Gravity.BOTTOM, 0, 0);
   toast.show();

代码示例来源:origin: BaronZ88/MinimalistWeather

/**
 * 向父容器中添加TextView
 *
 * @param text  TextView显示文字
 * @param color TextView的背景颜色,如:"#FADBCC"
 */
private void addTextView(Context context, String text, int color) {
  TextView textView = new TextView(context);
  textView.setBackgroundColor(color);
  textView.setText(text);
  textView.setTextColor(textColor);
  textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
  textView.setSingleLine();
  textView.setGravity(Gravity.CENTER);
  textView.setLayoutParams(new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0F));
  this.addView(textView);
}

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

TextView tv = new TextView(this);
tv.setTextSize(20);
tv.setBackgroundColor(0xff000033);
tv.setPadding(24, 8, 24, 24);
tv.setText(msg);
ll.addView(tv);
ListView lv = new ListView(this);

代码示例来源:origin: alibaba/Tangram-Android

@Override
public void postBindView(BaseCell cell) {
  int pos = cell.pos;
  String parent = "";
  if (cell.parent != null) {
    parent = cell.parent.getClass().getSimpleName();
  }
  textView.setText(
      cell.id + " pos: " + pos + " " + parent + " " + cell
          .optParam("msg"));
  if (pos > 57) {
    textView.setBackgroundColor(0x66cccf00 + (pos - 50) * 128);
  } else if (pos % 2 == 0) {
    textView.setBackgroundColor(0xaaaaff55);
  } else {
    textView.setBackgroundColor(0xcceeeeee);
  }
}

代码示例来源:origin: liaoinstan/SpringView

@Override
  public View getView(int position, View convertView, ViewGroup parent) {
    TextView item_text;
    if (convertView == null) {
      convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item, parent, false);
      item_text = convertView.findViewById(R.id.item_text);
      convertView.setTag(item_text);
    } else {
      item_text = (TextView) convertView.getTag();
    }
    if (position % 2 == 1) {
      item_text.setBackgroundColor(Color.parseColor("#e3f1fc"));
      item_text.setTextColor(Color.parseColor("#9dd2fc"));
    } else {
      item_text.setBackgroundColor(Color.parseColor("#ffffff"));
      item_text.setTextColor(Color.parseColor("#cccccc"));
    }
    item_text.setText(results.get(position));
    return convertView;
  }
}

代码示例来源:origin: gzu-liyujiang/AndroidPicker

cancelParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
cancelButton.setLayoutParams(cancelParams);
cancelButton.setBackgroundColor(Color.TRANSPARENT);
cancelButton.setGravity(Gravity.CENTER);
int padding = ConvertUtils.toPx(activity, topPadding);
cancelButton.setPadding(padding, 0, padding, 0);
if (!TextUtils.isEmpty(cancelText)) {
  cancelButton.setText(cancelText);
  textView.setGravity(Gravity.CENTER);
  if (!TextUtils.isEmpty(titleText)) {
    textView.setText(titleText);
submitParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
submitButton.setLayoutParams(submitParams);
submitButton.setBackgroundColor(Color.TRANSPARENT);
submitButton.setGravity(Gravity.CENTER);
submitButton.setPadding(padding, 0, padding, 0);
if (!TextUtils.isEmpty(submitText)) {
  submitButton.setText(submitText);

相关文章

微信公众号

最新文章

更多

TextView类方法