本文整理汇总了Java中android.widget.TextView.setBackground方法的典型用法代码示例。如果您正苦于以下问题:Java TextView.setBackground方法的具体用法?Java TextView.setBackground怎么用?Java TextView.setBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.TextView
的用法示例。
在下文中一共展示了TextView.setBackground方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onBindViewHolder
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
TextView textView = ((NumberSelectionViewHolder) holder).getTextView();
if (textView == null) {
return;
}
textView.setText(String.valueOf(position + 1));
boolean currentIsSelected = mCurrentSelected != null && mCurrentSelected == position + 1;
textView.setTextColor(ContextCompat.getColor(textView.getContext(), currentIsSelected ? R.color.white : R.color.primary_text));
textView.setTypeface(null, currentIsSelected ? Typeface.BOLD : Typeface.NORMAL);
textView.setBackground(textView.getContext().getDrawable(currentIsSelected ? R.drawable.selected_background_rounded : R.drawable.selectable_background_rounded));
holder.itemView.setOnClickListener(v -> mOnClickListener.numberSelected(position));
}
示例2: updateTextAndColor
import android.widget.TextView; //导入方法依赖的package包/类
private void updateTextAndColor(TextView categoryView, int count, TextView countView, int[] colors) {
categoryView.setBackgroundColor(colors[2]);
categoryView.setTextColor(colors[3]);
GradientDrawable countD = new GradientDrawable();
countD.setColor(colors[0]);
countD.setCornerRadius(countView.getHeight() / 2);
countView.setBackground(countD);
countView.setTextColor(colors[1]);
int c = count;
if (countView == mCountRecent) {
int recent = activity.getResources().getInteger(R.integer.sheet_recent_count);
c = count > recent ? recent : c;
}
countView.setText(String.valueOf(c));
}
示例3: getTextView
import android.widget.TextView; //导入方法依赖的package包/类
/**
* 获得一个设置好属性的TextView
*
* @param msg
* @return
*/
public TextView getTextView(String msg) {
TextView tv = new TextView(mContext);
tv.setLayoutParams(lp_WW);
tv.setText(msg);
tv.setTextColor(defaultTextColor);
Drawable background = null;
if (defaultBackgroundResid != null) {
background = mContext.getResources().getDrawable(defaultBackgroundResid);
} else {
background = defaultBackgroundColor;
}
if (currentapiVersion > 10) tv.setBackground(background);
else tv.setBackgroundDrawable(background);
tv.setPadding(5, 5, 5, 5);
tv.setGravity(Gravity.CENTER);
return tv;
}
示例4: inflateTextView
import android.widget.TextView; //导入方法依赖的package包/类
private TextView inflateTextView() {
GradientDrawable shape = new GradientDrawable();
shape.setCornerRadius(8);
shape.setColor(0xff000000 | mRandom.nextInt(0x00ffffff));
TextView textView = new TextView(this);
textView.setGravity(Gravity.CENTER);
textView.setTextColor(Color.WHITE);
textView.setWidth(150 + mRandom.nextInt(3) * 50);
textView.setHeight(150 + mRandom.nextInt(3) * 50);
textView.setTextSize(32);
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN) {
textView.setBackgroundDrawable(shape);
} else {
textView.setBackground(shape);
}
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View view) {
mList.removeViewWithAnimation(view);
}
});
textView.setText(String.format(Locale.JAPAN, "%1$02d", mCounter++));
return textView;
}
示例5: createTag
import android.widget.TextView; //导入方法依赖的package包/类
private void createTag(String s, @ColorInt int tintColor) {
TextView textView = new TextView(getContext());
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
lp.rightMargin = dp2px(4);
textView.setLayoutParams(lp);
textView.setTextSize(9);
Drawable drawable = ContextCompat.getDrawable(getContext(), R.drawable.shape_round_stroke_bg_tag);
DrawableCompat.setTint(drawable, tintColor);
if (Build.VERSION.SDK_INT > 15)
textView.setBackground(drawable);
else
textView.setBackgroundDrawable(drawable);
textView.setPadding(dp2px(2), 0, dp2px(2), 0);
textView.setText(s);
addView(textView);
}
示例6: createClusterIcon
import android.widget.TextView; //导入方法依赖的package包/类
@NonNull
private BitmapDescriptor createClusterIcon(int clusterBucket) {
@SuppressLint("InflateParams")
TextView clusterIconView = (TextView) LayoutInflater.from(mContext)
.inflate(R.layout.map_cluster_icon, null);
clusterIconView.setBackground(createClusterBackground());
clusterIconView.setTextColor(mIconStyle.getClusterTextColor());
clusterIconView.setTextSize(TypedValue.COMPLEX_UNIT_PX,
mIconStyle.getClusterTextSize());
clusterIconView.setText(getClusterIconText(clusterBucket));
clusterIconView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
clusterIconView.layout(0, 0, clusterIconView.getMeasuredWidth(),
clusterIconView.getMeasuredHeight());
Bitmap iconBitmap = Bitmap.createBitmap(clusterIconView.getMeasuredWidth(),
clusterIconView.getMeasuredHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(iconBitmap);
clusterIconView.draw(canvas);
return BitmapDescriptorFactory.fromBitmap(iconBitmap);
}
示例7: initView
import android.widget.TextView; //导入方法依赖的package包/类
private void initView(Context context) {
mTextView = new TextView(context);
mClickToShow = new TextView(context);
mTextView.setTextSize(textSize);
mTextView.setTextColor(textColor);
mTextView.setMaxLines(showLine);
mClickToShow.setBackground(getResources().getDrawable(R.drawable.selector_tx_show_more));
mClickToShow.setTextSize(textSize);
mClickToShow.setTextColor(getResources().getColor(R.color.nick));
mClickToShow.setText(clickText);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
params.topMargin = UIHelper.dipToPx(10f);
mClickToShow.setLayoutParams(params);
mClickToShow.setOnClickListener(this);
setOrientation(VERTICAL);
addView(mTextView);
addView(mClickToShow);
}
示例8: setUpDays
import android.widget.TextView; //导入方法依赖的package包/类
/**
* Sets up view for showing completed days
* @param ctx
*/
public static void setUpDays(Activity ctx) {
LinearLayout daysOuter = (LinearLayout) ctx.findViewById(R.id.days_outer);
View childdays = ctx.getLayoutInflater().inflate(R.layout.days, null);
// Setting things
for (int i = 0; i < 7; i++) {
final TextView dayTextView = (TextView) childdays.findViewById(AddHabitActivity.daytags[i]);
final int currenti = i;
if (AddHabitActivity.days[i] == 1) {
dayTextView.setBackground(ctx.getDrawable(R.drawable.days_border_valid));
}
}
LinearLayout daysInner = (LinearLayout) childdays.findViewById(R.id.days_inner);
daysInner.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
daysOuter.addView(childdays);
}
示例9: captureTextBitmap
import android.widget.TextView; //导入方法依赖的package包/类
private static Bitmap captureTextBitmap(TextView textView) {
Drawable background = textView.getBackground();
textView.setBackground(null);
int width = textView.getWidth() - textView.getPaddingLeft() - textView.getPaddingRight();
int height = textView.getHeight() - textView.getPaddingTop() - textView.getPaddingBottom();
if (width == 0 || height == 0) {
return null;
}
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(bitmap);
canvas.translate(-textView.getPaddingLeft(), -textView.getPaddingTop());
textView.draw(canvas);
textView.setBackground(background);
return bitmap;
}
示例10: styleBackground
import android.widget.TextView; //导入方法依赖的package包/类
private void styleBackground() {
TextView textView = getSelfView().getBinding().textView;
if (builder.backgroundDrawable != 0) {
textView.setBackground(getContext().getResources().getDrawable(builder.backgroundDrawable));
} else if (builder.backgroundColor != 0) {
textView.setBackgroundResource(builder.backgroundColor);
}
}
示例11: init
import android.widget.TextView; //导入方法依赖的package包/类
private void init() {
Bundle bundle = getArguments();
mExchangedAward = (ExchangedAward) bundle.getSerializable(TAG_EXCHANGE_AWARD);
Toolbar toolbar = (Toolbar) getActivity().findViewById(R.id.toolbar);
toolbar.setTitle(mExchangedAward.getTitle());
Log.v("DEBUG2", "" + mExchangedAward.getCode());
mTitle = (TextView) mView.findViewById(R.id.qr_title);
mTitle.setText(mExchangedAward.getTitle());
mBusiness = (TextView) mView.findViewById(R.id.qr_business);
mBusiness.setText(mExchangedAward.getCommerceOffering());
mDate = (TextView) mView.findViewById(R.id.qr_date);
mDate.setText(getString(EXCHANGED_ON) + ' ' + mSimpleDateFormat.format(mExchangedAward
.getCreatedAt()));
mQrcode = (ImageView) mView.findViewById(R.id.qr_qrcode);
try {
if (mExchangedAward.getCode() != null) {
Bitmap bitmap = encodeAsBitmap(mExchangedAward.getCode());
mQrcode.setImageBitmap(bitmap);
}
} catch (WriterException e) {
e.printStackTrace();
}
mTextQrcode = (TextView) mView.findViewById(R.id.qr_textQrcode);
mTextQrcode.setText(mExchangedAward.getCode());
mStateText = (TextView) mView.findViewById(R.id.qr_state_text);
// USED/VALID indicator
mStateText.setText(getContext().getString(mExchangedAward.isUsed()
? AWARD_USED : AWARD_VALID));
// Indicator background
if (VERSION.SDK_INT >= VERSION_CODES.JELLY_BEAN) {
mStateText.setBackground(ContextCompat.getDrawable(getContext(),
mExchangedAward.isUsed() ? COLOR_USED : COLOR_VALID));
}
setMoreInfoTextButton();
}
示例12: getMoreView
import android.widget.TextView; //导入方法依赖的package包/类
@Override
public View getMoreView(int moreItemsCount, View convertView, ViewGroup parent) {
final View root = LayoutInflater.from(parent.getContext()).inflate(R.layout.view_counter, parent, false);
final TextView view = (TextView) root.findViewById(R.id.text);
view.setBackground(ContextCompat.getDrawable(parent.getContext(), R.drawable.round_counter));
view.setText(String.valueOf(moreItemsCount));
return root;
}
示例13: addTableColumnNames
import android.widget.TextView; //导入方法依赖的package包/类
private void addTableColumnNames(Table table) {
TableRow columnRow = new TableRow(this);
TextView serialNoCell = getCellView(getString(R.string.serial_number_column_heading));
serialNoCell.setTypeface(null, Typeface.BOLD);
columnRow.addView(serialNoCell);
for (String column : table.getColumns()) {
TextView columnView = getCellView(column);
columnView.setBackgroundColor(ContextCompat.getColor(this, R.color.snooper_grey));
columnView.setBackground(ContextCompat.getDrawable(this, R.drawable.table_cell_background));
columnView.setTypeface(null, Typeface.BOLD);
columnRow.addView(columnView);
}
tableLayout.addView(columnRow);
}
示例14: getCellView
import android.widget.TextView; //导入方法依赖的package包/类
@NonNull
private TextView getCellView(String cellValue) {
TextView textView = new TextView(this);
textView.setPadding(1, 0, 0, 0);
textView.setBackground(ContextCompat.getDrawable(this, R.drawable.table_cell_background));
textView.setText(cellValue);
return textView;
}
示例15: setBlurLevelTextBackground
import android.widget.TextView; //导入方法依赖的package包/类
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private void setBlurLevelTextBackground(TextView tv) {
mBlurLevels[0].setBackground(context.getResources().getDrawable(R.drawable.zero_blur_level_item_unselected));
for (int i = 1; i < BLUR_LEVEL_TV_ID.length; i++) {
mBlurLevels[i].setBackground(context.getResources().getDrawable(R.drawable.blur_level_item_unselected));
}
if (tv == mBlurLevels[0]) {
tv.setBackground(context.getResources().getDrawable(R.drawable.zero_blur_level_item_selected));
} else {
tv.setBackground(context.getResources().getDrawable(R.drawable.blur_level_item_selected));
}
}