當前位置: 首頁>>代碼示例>>Java>>正文


Java ForegroundColorSpan類代碼示例

本文整理匯總了Java中android.text.style.ForegroundColorSpan的典型用法代碼示例。如果您正苦於以下問題:Java ForegroundColorSpan類的具體用法?Java ForegroundColorSpan怎麽用?Java ForegroundColorSpan使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ForegroundColorSpan類屬於android.text.style包,在下文中一共展示了ForegroundColorSpan類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getDesignationText

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
public SpannableString getDesignationText()
{
    String text = txtDesignation.getText().toString();

    SpannableString s = new SpannableString(text);

    s.setSpan(new ForegroundColorSpan(getResources().getColor(R.color.colorAccent)), text.indexOf("@"), text.length(), 0);

    /*
    s.setSpan(new RelativeSizeSpan(1.2f), text.indexOf("A"), text.length(), 0);
    s.setSpan(new StyleSpan(Typeface.NORMAL), text.indexOf("A"), text.length(), 0);
    s.setSpan(new ForegroundColorSpan(Color.BLACK), text.indexOf("A"), text.length(), 0);
    */

    return s;
}
 
開發者ID:wajahatkarim3,項目名稱:Quizca-UI-Concept,代碼行數:17,代碼來源:MainActivity.java

示例2: onBindViewHolder

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
@Override
public void onBindViewHolder(ResultViewHolder viewHolder, int position) {
    SearchItem item = mResultList.get(position);

    viewHolder.icon_left.setImageResource(item.get_icon());
    viewHolder.icon_left.setColorFilter(SearchView.getIconColor(), PorterDuff.Mode.SRC_IN);
    viewHolder.text.setTypeface((Typeface.create(SearchView.getTextFont(), SearchView.getTextStyle())));
    viewHolder.text.setTextColor(SearchView.getTextColor());

    String itemText = item.get_text().toString();
    String itemTextLower = itemText.toLowerCase(Locale.getDefault());

    if (itemTextLower.contains(key) && !key.isEmpty()) {
        SpannableString s = new SpannableString(itemText);
        s.setSpan(new ForegroundColorSpan(SearchView.getTextHighlightColor()), itemTextLower.indexOf(key), itemTextLower.indexOf(key) + key.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        viewHolder.text.setText(s, TextView.BufferType.SPANNABLE);
    } else {
        viewHolder.text.setText(item.get_text());
    }
}
 
開發者ID:sega4revenge,項目名稱:Sega,代碼行數:21,代碼來源:SearchAdapter.java

示例3: highlightText

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
private Spannable highlightText(String text) {
    Spannable highlightedSpannable = Spannable.Factory.getInstance().newSpannable(text);

    if (highlight == null) {
        return highlightedSpannable;
    }

    Pattern pattern = Pattern.compile(highlight, Pattern.LITERAL | Pattern.CASE_INSENSITIVE);
    Matcher matcher = pattern.matcher(text);
    while (matcher.find()) {
        highlightedSpannable.setSpan(
                new ForegroundColorSpan(context.getResources().getColor(android.R.color.holo_blue_light)),
                matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    }

    return highlightedSpannable;
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:18,代碼來源:RecipientAdapter.java

示例4: setCheckInUI

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
private void setCheckInUI(int count, boolean isChecked) {
    boolean z;
    String message = String.format(getString(R.string.d7), new Object[]{Integer.valueOf
            (count)});
    SpannableString ss = new SpannableString(message);
    ss.setSpan(new ForegroundColorSpan(SupportMenu.CATEGORY_MASK), 5, message.length() - 1, 33);
    this.checkInMsgText.setText(ss);
    this.checkInBtn.setText(isChecked ? R.string.d4 : R.string.d6);
    TextView textView = this.checkInBtn;
    if (isChecked) {
        z = false;
    } else {
        z = true;
    }
    textView.setEnabled(z);
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:StatusBlockFragment.java

示例5: highlightParamTextOffsetRightOne

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
public static SpannableString highlightParamTextOffsetRightOne(String inputString, String highlight, int color) {
    inputString = String.format(inputString, new Object[]{highlight});
    SpannableString spanString = new SpannableString(inputString);
    if (!TextUtils.isEmpty(inputString)) {
        int beginPos = inputString.indexOf(highlight);
        if (beginPos > -1) {
            int endPos;
            if ((highlight.length() + beginPos) + 1 > inputString.length()) {
                endPos = inputString.length();
            } else {
                endPos = (highlight.length() + beginPos) + 1;
            }
            spanString.setSpan(new ForegroundColorSpan(color), beginPos, endPos, 33);
        }
    }
    return spanString;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:18,代碼來源:StringUtils.java

示例6: internalUpdate

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
@Override
protected void internalUpdate(XySeriesInfo seriesInfo) {
    final SpannableStringBuilder sb = new SpannableStringBuilder();
    sb.append(modifierName).append(StringUtil.NEW_LINE);

    if (seriesInfo.seriesName != null) {
        sb.append(seriesInfo.seriesName);
        sb.setSpan(new ForegroundColorSpan(ColorUtil.Black), 0, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        sb.append(StringUtil.NEW_LINE);
    }

    sb.append("X: ").append(seriesInfo.getFormattedXValue());
    sb.append(" Y: ").append(seriesInfo.getFormattedYValue());

    setText(sb);

    // stroke 0xffff4500
    setSeriesColor(0xffe2460c);
}
 
開發者ID:ABTSoftware,項目名稱:SciChart.Android.Examples,代碼行數:20,代碼來源:CustomTooltipsWithModifiersFragment.java

示例7: convert

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
@Override
public void convert(EasyLVHolder holder, int position, BookMark item) {
    TextView tv = holder.getView(R.id.tvMarkItem);

    SpannableString spanText = new SpannableString((position + 1) + ". " + item.title + ": ");
    spanText.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.light_coffee)),
            0, spanText.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);

    tv.setText(spanText);

    if (item.desc != null) {
        tv.append(item.desc
                .replaceAll(" ", "")
                .replaceAll(" ", "")
                .replaceAll("\n", ""));
    }

}
 
開發者ID:ynztlxdeai,項目名稱:TextReader,代碼行數:19,代碼來源:BookMarkAdapter.java

示例8: getHighLightKeyWord

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
/** 
    * @param color 關鍵字顏色 
    * @param text 文本 
    * @param keyword 多個關鍵字 
    * @return 
    */  
   public static SpannableString getHighLightKeyWord(int color, String text, String[] keyword)
{  
       SpannableString s = new SpannableString(text);  
       for (int i = 0; i < keyword.length; i++)
	{  
           Pattern p = Pattern.compile(keyword[i]);  
           Matcher m = p.matcher(s);  
           while (m.find())
		{  
               int start = m.start();  
               int end = m.end();  
               s.setSpan(new ForegroundColorSpan(color), start, end, 
					  Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);  
           }  
       }  
       return s;  

   }
 
開發者ID:stytooldex,項目名稱:stynico,代碼行數:25,代碼來源:HighLightKeyWordUtil.java

示例9: setFeeValue

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
@Override
    public void setFeeValue(Fee fee) {
        if (fee != null || 1 == getIntent().getIntExtra("type", OrderStatus.ORDER_STATUS_DETAIL)) {
            totalAmount = fee.getMoney().getTotalAmount();
            if (mOrderDetail.getCouponList() == null || mOrderDetail.getCouponList().getCoupon() == null || mOrderDetail.getCouponList().getCoupon().getName().equals("")) {
                mTextView_Coupon_Value.setText("有" + fee.getCouponNumber() + "張可用");
            }
//            mTextView_Fee.setText("運費:" + CommonUtils.doubleFormat(fee.getMoney().getTotalAmount()));

            SpannableString styledText = new SpannableString("運費:¥"+CommonUtils.doubleFormat(fee.getMoney().getTotalAmount()));
            int color = getResources().getColor(R.color.my_yellow);
            styledText.setSpan(new ForegroundColorSpan(color), 0, 3, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
            mTextView_Fee.setText(styledText);

            mOrderDetail.setValueAddedlist(fee.getValueAddedlist());
            this.fee = fee.getMoney().getTotalAmount();
        }
    }
 
開發者ID:Zyj163,項目名稱:yyox,代碼行數:19,代碼來源:OrderDetailActivity.java

示例10: bind

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
public void bind(ServerLogsEntry entry, int pos) {
    int colorId = R.color.storageSettingsChartOthers;
    if (entry.size > 0L) {
        if (pos == 0)
            colorId = R.color.storageSettingsChartFirst;
        else if (pos == 1)
            colorId = R.color.storageSettingsChartSecond;
        else if (pos == 2)
            colorId = R.color.storageSettingsChartThird;
    }
    ColoredTextBuilder builder = new ColoredTextBuilder();
    builder.append(entry.name, new ForegroundColorSpan(mText.getResources().getColor(colorId)));
    builder.append("  ");
    builder.append(formatFileSize(entry.size));
    mText.setText(builder.getSpannable());
    mText.setTag(entry.uuid);
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:18,代碼來源:StorageSettingsAdapter.java

示例11: onBindViewHolder

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
@Override
protected void onBindViewHolder(@NonNull IOSItemBinder.ViewHolder viewHolder,
                                @NonNull IOS ios) {
    SpannableString span = new SpannableString(new StringBuilder()
            .append(ios.content)
            .append("(via-")
            .append(ios.author)
            .append(")"));
    span.setSpan(new ForegroundColorSpan(Color.parseColor("#9e9e9e"))
            , ios.content.length()
            , span.length()
            , Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    viewHolder.content.setText(span);
    viewHolder.url = ios.url;
    viewHolder.title = ios.content;
}
 
開發者ID:Shuanghua,項目名稱:LikeGank,代碼行數:17,代碼來源:IOSItemBinder.java

示例12: show

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
static void show(View parent,
                 CharSequence text,
                 int duration,
                 @ColorInt int textColor,
                 @ColorInt int bgColor,
                 CharSequence actionText,
                 @ColorInt int actionTextColor,
                 View.OnClickListener listener) {
    SpannableString spannableString = new SpannableString(text);
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor);
    spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration));
    Snackbar snackbar = snackbarWeakReference.get();
    View view = snackbar.getView();
    view.setBackgroundColor(bgColor);
    if (actionText != null && actionText.length() > 0 && listener != null) {
        snackbar.setActionTextColor(actionTextColor);
        snackbar.setAction(actionText, listener);
    }
    snackbar.show();

}
 
開發者ID:Justson,項目名稱:AgentWeb,代碼行數:23,代碼來源:AgentWebUtils.java

示例13: handleMidrowCtrl

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
private void handleMidrowCtrl(byte cc2) {
  // TODO: support the extended styles (i.e. backgrounds and transparencies)

  // cc2 - 0|0|1|0|ATRBT|U
  // ATRBT is the 3-byte encoded attribute, and U is the underline toggle
  boolean isUnderlined = (cc2 & 0x01) == 0x01;
  currentCueBuilder.setUnderline(isUnderlined);

  int attribute = (cc2 >> 1) & 0x0F;
  if (attribute == 0x07) {
    currentCueBuilder.setMidrowStyle(new StyleSpan(Typeface.ITALIC), 2);
    currentCueBuilder.setMidrowStyle(new ForegroundColorSpan(Color.WHITE), 1);
  } else {
    currentCueBuilder.setMidrowStyle(new ForegroundColorSpan(COLORS[attribute]), 1);
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:17,代碼來源:Cea608Decoder.java

示例14: handleTagNode

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
@Override public void handleTagNode(TagNode node, SpannableStringBuilder builder, int start, int end) {
    if (isPre) {
        StringBuffer buffer = new StringBuffer();
        buffer.append("\n");//fake padding top + make sure, pre is always by itself
        getPlainText(buffer, node);
        buffer.append("\n");//fake padding bottom + make sure, pre is always by itself
        builder.append(replace(buffer.toString()));
        builder.append("\n");
        builder.setSpan(new CodeBackgroundRoundedSpan(color), start, builder.length(), SPAN_EXCLUSIVE_EXCLUSIVE);
        builder.append("\n");
        this.appendNewLine(builder);
        this.appendNewLine(builder);
    } else {
        StringBuffer text = node.getText();
        builder.append(" ");
        builder.append(replace(text.toString()));
        builder.append(" ");
        final int stringStart = start + 1;
        final int stringEnd = builder.length() - 1;
        builder.setSpan(new BackgroundColorSpan(color), stringStart, stringEnd, SPAN_EXCLUSIVE_EXCLUSIVE);
        if (theme == PrefGetter.LIGHT) {
            builder.setSpan(new ForegroundColorSpan(Color.RED), stringStart, stringEnd, SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        builder.setSpan(new TypefaceSpan("monospace"), stringStart, stringEnd, SPAN_EXCLUSIVE_EXCLUSIVE);
    }
}
 
開發者ID:duyp,項目名稱:mvvm-template,代碼行數:27,代碼來源:PreTagHandler.java

示例15: createColorPicker

import android.text.style.ForegroundColorSpan; //導入依賴的package包/類
@Override
protected ColorListPickerDialog createColorPicker(boolean fillColor, int selectedColor) {
    ColorListPickerDialog ret = super.createColorPicker(fillColor, selectedColor);
    if (!fillColor) {
        ret.setColors(getResources().getIntArray(R.array.formatTextColors), -1);
        ret.setSelectedColor(selectedColor);
        ret.setNeutralButton(R.string.message_format_sender_color,
                (DialogInterface dialog, int which) -> {
                    setSpan(new MessageBuilder.MetaForegroundColorSpan(getContext(),
                            MessageBuilder.MetaForegroundColorSpan.COLOR_SENDER));
                });
        ret.setOnColorChangeListener((ColorListPickerDialog d, int newColorIndex, int color) -> {
            removeSpan(ForegroundColorSpan.class);
            if (color == IRCColorUtils.getStatusTextColor(getContext()))
                setSpan(new MessageBuilder.MetaForegroundColorSpan(getContext(), MessageBuilder.MetaForegroundColorSpan.COLOR_STATUS));
            if (color == IRCColorUtils.getTimestampTextColor(getContext()))
                setSpan(new MessageBuilder.MetaForegroundColorSpan(getContext(), MessageBuilder.MetaForegroundColorSpan.COLOR_TIMESTAMP));
            else
                setSpan(new ForegroundColorSpan(color));
            d.cancel();
        });
    }
    return ret;
}
 
開發者ID:MCMrARM,項目名稱:revolution-irc,代碼行數:25,代碼來源:MessageFormatSettingsFormatBar.java


注:本文中的android.text.style.ForegroundColorSpan類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。