当前位置: 首页>>代码示例>>Java>>正文


Java TextView.setBackground方法代码示例

本文整理汇总了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));
}
 
开发者ID:barnhill,项目名称:SimpleBible,代码行数:19,代码来源:NumberSelectionAdapter.java

示例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));

    }
 
开发者ID:DuanJiaNing,项目名称:Musicoco,代码行数:20,代码来源:MainSheetsController.java

示例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;
}
 
开发者ID:jeasinlee,项目名称:AndroidBasicLibs,代码行数:24,代码来源:DrawerToast.java

示例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;
}
 
开发者ID:sjnyag,项目名称:AnimationWrapLayout,代码行数:25,代码来源:MainActivity.java

示例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);
}
 
开发者ID:woxingxiao,项目名称:GracefulMovies,代码行数:18,代码来源:TagGroup.java

示例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);
}
 
开发者ID:sharewire,项目名称:google-maps-clustering,代码行数:25,代码来源:DefaultIconGenerator.java

示例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);
}
 
开发者ID:HowieTianDev,项目名称:ChenYan,代码行数:24,代码来源:ClickShowMoreLayout.java

示例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);

}
 
开发者ID:CMPUT301F17T17,项目名称:Habitizer,代码行数:27,代码来源:AddHabitActivity.java

示例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;
}
 
开发者ID:googlesamples,项目名称:android-instant-apps,代码行数:16,代码来源:TextResize.java

示例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);
    }
}
 
开发者ID:Mindjet,项目名称:LiteReader,代码行数:9,代码来源:ButtonViewModel.java

示例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();
}
 
开发者ID:ArnauBlanch,项目名称:civify-app,代码行数:38,代码来源:ShowQrFragment.java

示例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;
}
 
开发者ID:AppliKey,项目名称:ImageMore,代码行数:9,代码来源:Adapter.java

示例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);
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:15,代码来源:TableDetailActivity.java

示例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;
}
 
开发者ID:jainsahab,项目名称:AndroidSnooper,代码行数:9,代码来源:TableDetailActivity.java

示例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));
    }
}
 
开发者ID:newDeepLearing,项目名称:decoy,代码行数:13,代码来源:FaceULayout.java


注:本文中的android.widget.TextView.setBackground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。