當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。