Java 类android.text.style.ForegroundColorSpan 实例源码
项目:Quizca-UI-Concept
文件:MainActivity.java
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;
}
项目:Sega
文件:SearchAdapter.java
@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());
}
}
项目:q-mail
文件:RecipientAdapter.java
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;
}
项目:boohee_v5.6
文件:StatusBlockFragment.java
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);
}
项目:letv
文件:StringUtils.java
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;
}
项目:SciChart.Android.Examples
文件:CustomTooltipsWithModifiersFragment.java
@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);
}
项目:TextReader
文件:BookMarkAdapter.java
@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", ""));
}
}
项目:stynico
文件:HighLightKeyWordUtil.java
/**
* @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;
}
项目:yyox
文件:OrderDetailActivity.java
@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();
}
}
项目:revolution-irc
文件:StorageSettingsAdapter.java
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);
}
项目:LikeGank
文件:IOSItemBinder.java
@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;
}
项目:AgentWeb
文件:AgentWebUtils.java
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();
}
项目:Exoplayer2Radio
文件:Cea608Decoder.java
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);
}
}
项目:SciChart.Android.Examples
文件:CustomTooltipsWithModifiersFragment.java
@Override
protected void internalUpdate(XySeriesInfo seriesInfo) {
final SpannableStringBuilder sb = new SpannableStringBuilder();
sb.append("X: ").append(seriesInfo.getFormattedXValue()).append(StringUtil.NEW_LINE);
sb.append("Y: ").append(seriesInfo.getFormattedYValue()).append(StringUtil.NEW_LINE);
if (seriesInfo.seriesName != null) {
final int start = sb.length();
sb.append(seriesInfo.seriesName);
sb.setSpan(new ForegroundColorSpan(ColorUtil.White), start, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
sb.append(StringUtil.NEW_LINE);
}
sb.append(modifierName);
setText(sb);
// stroke 0xff4d81dd
setSeriesColor(0xff6495ed);
}
项目:mvvm-template
文件:PreTagHandler.java
@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);
}
}
项目:revolution-irc
文件:MessageFormatSettingsFormatBar.java
@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;
}
项目:sctalk
文件:IMUIHelper.java
public static void setTextHilighted(TextView textView, String text,SearchElement searchElement) {
textView.setText(text);
if (textView == null
|| TextUtils.isEmpty(text)
|| searchElement ==null) {
return;
}
int startIndex = searchElement.startIndex;
int endIndex = searchElement.endIndex;
if (startIndex < 0 || endIndex > text.length()) {
return;
}
// 开始高亮处理
int color = Color.rgb(69, 192, 26);
textView.setText(text, BufferType.SPANNABLE);
Spannable span = (Spannable) textView.getText();
span.setSpan(new ForegroundColorSpan(color), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
项目:revolution-irc
文件:TextFormatBar.java
protected ColorListPickerDialog createColorPicker(boolean fillColor, int selectedColor) {
ColorListPickerDialog dialog = new ColorListPickerDialog(getContext());
if (!fillColor) {
dialog.setTitle(R.string.format_text_color);
} else {
dialog.setTitle(R.string.format_fill_color);
}
dialog.setSelectedColor(selectedColor);
dialog.setPositiveButton(R.string.action_cancel, null);
dialog.setOnColorChangeListener((ColorListPickerDialog d, int newColorIndex, int color) -> {
if (!fillColor) {
removeSpan(ForegroundColorSpan.class);
setSpan(new ForegroundColorSpan(color));
} else {
removeSpan(BackgroundColorSpan.class);
setSpan(new BackgroundColorSpan(color));
}
d.cancel();
});
return dialog;
}
项目:AndroidUtilCode-master
文件:SnackbarUtils.java
/**
* 设置snackbar文字和背景颜色
*
* @param parent 父视图(CoordinatorLayout或者DecorView)
* @param text 文本
* @param duration 显示时长
* @param textColor 文本颜色
* @param bgColor 背景色
* @param actionText 事件文本
* @param actionTextColor 事件文本颜色
* @param listener 监听器
*/
private 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();
}
项目:orgzly-android
文件:BookUtils.java
private static CharSequence replaceWithLastActionError(Context context, Book book, CharSequence str) {
BookAction action = book.getLastAction();
if (action != null && action.getType() == BookAction.Type.ERROR) {
SpannableStringBuilder builder = new SpannableStringBuilder(action.getMessage());
/* Get error color attribute. */
TypedArray arr = context.obtainStyledAttributes(
new int[]{R.attr.item_book_error_color});
int color = arr.getColor(0, 0);
arr.recycle();
/* Set error color. */
builder.setSpan(new ForegroundColorSpan(color), 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return builder;
}
return str;
}
项目:Intelligent_Indoor_Localization_System
文件:J2xxHyperTerm.java
void appendData(String data)
{
if(true == bContentFormatHex)
{
if(timesMessageHexFormatWriteData < 3)
{
timesMessageHexFormatWriteData++;
midToast("The writing data won��t be showed on data area while content format is hexadecimal format.",Toast.LENGTH_LONG);
}
return;
}
if(true == bSendHexData)
{
SpannableString text = new SpannableString(data);
text.setSpan(new ForegroundColorSpan(Color.YELLOW), 0, data.length(), 0);
//readText.append(text);
bSendHexData = false;
}
else
{
read_zigbee(data);
}
}
项目:revolution-irc
文件:ChannelSearchDialog.java
@Override
public void bind(Pair<ServerConnectionInfo, String> item) {
String name = item.first.getName();
String channel = item.second;
int iof = channel.indexOf(mHighlightQuery);
SpannableString str = new SpannableString(channel + " " + name);
str.setSpan(new ForegroundColorSpan(mHighlightTextColor), iof, iof + mHighlightQuery.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
str.setSpan(new ForegroundColorSpan(mSecondaryTextColor), channel.length() + 2, channel.length() + 2 + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mText.setText(str);
}
项目:decoy
文件:AitHelper.java
public static void replaceAitForeground(String value, SpannableString mSpannableString) {
if (TextUtils.isEmpty(value) || TextUtils.isEmpty(mSpannableString)) {
return;
}
Pattern pattern = Pattern.compile("(\\[有人@你\\])");
Matcher matcher = pattern.matcher(value);
while (matcher.find()) {
int start = matcher.start();
if (start != 0) {
continue;
}
int end = matcher.end();
mSpannableString.setSpan(new ForegroundColorSpan(Color.RED), start, end, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
}
}
项目:showroom-android
文件:OuterItem.java
void setContent(@NonNull List<InnerData> innerDataList) {
final Context context = itemView.getContext();
final InnerData header = innerDataList.subList(0, 1).get(0);
final List<InnerData> tail = innerDataList.subList(1, innerDataList.size());
mRecyclerView.setLayoutManager(new InnerLayoutManager());
((InnerAdapter) mRecyclerView.getAdapter()).addData(tail);
Glide.with(context)
.load(header.avatarUrl)
.placeholder(R.drawable.gv_avatar_placeholder)
.bitmapTransform(new CropCircleTransformation(context))
.into(mAvatar);
final String title1 = header.title + "?";
final Spannable title2 = new SpannableString(header.title + "? - " + header.name);
title2.setSpan(new AbsoluteSizeSpan(mTitleSize1), 0, title1.length(), SPAN_INCLUSIVE_INCLUSIVE);
title2.setSpan(new AbsoluteSizeSpan(mTitleSize2), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE);
title2.setSpan(new ForegroundColorSpan(Color.argb(204, 255, 255, 255)), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE);
mHeaderCaption1.setText(title1);
mHeaderCaption2.setText(title2);
mName.setText(String.format("%s %s", header.name, context.getString(R.string.gv_asked)));
mInfo.setText(String.format("%s %s · %s", header.age, context.getString(R.string.gv_years), header.address));
}
项目:yjPlay
文件:GestureVideoPlayer.java
/****
* 滑动进度
*
* @param seekTimePosition 滑动的时间
* @param duration 视频总长
* @param seekTime 滑动的时间 格式化00:00
* @param totalTime 视频总长 格式化00:00
**/
private void showProgressDialog(long seekTimePosition, long duration, String seekTime, String totalTime) {
newPosition = seekTimePosition;
if (onGestureProgressListener != null) {
onGestureProgressListener.showProgressDialog(seekTimePosition, duration, seekTime, totalTime);
} else {
String stringBuilder = seekTime + "/" + totalTime;
ForegroundColorSpan blueSpan = new ForegroundColorSpan(ContextCompat.getColor(activity, R.color.simple_exo_style_color));
SpannableString spannableString = new SpannableString(stringBuilder);
spannableString.setSpan(blueSpan, 0, seekTime.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
getPlayerViewListener().setTimePosition(spannableString);
}
}
项目:q-mail
文件:MessageListAdapter.java
private void formatPreviewText(TextView preview, CharSequence beforePreviewText, String sigil) {
Spannable previewText = (Spannable)preview.getText();
previewText.setSpan(buildSenderSpan(), 0, beforePreviewText.length() + sigil.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
int previewSpanColor = buildPreviewSpanColor();
// Set span (color) for preview message
previewText.setSpan(new ForegroundColorSpan(previewSpanColor), beforePreviewText.length() + sigil.length(),
previewText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
项目:q-mail
文件:ICalendarHelper.java
@VisibleForTesting
static CharSequence toFriendly(Organizer organizer, Contacts contacts,
boolean showCorrespondentNames,
boolean changeContactNameColor,
int contactNameColor) {
if (organizer == null) {
return null;
}
if (!showCorrespondentNames) {
return organizer.getEmail();
} else if (contacts != null) {
final String name = contacts.getNameForAddress(organizer.getEmail());
// TODO: The results should probably be cached for performance reasons.
if (name != null) {
if (changeContactNameColor) {
final SpannableString coloredName = new SpannableString(name);
coloredName.setSpan(new ForegroundColorSpan(contactNameColor),
0,
coloredName.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE
);
return coloredName;
} else {
return name;
}
}
}
return (!TextUtils.isEmpty(organizer.getCommonName())) ? organizer.getCommonName() : organizer.getEmail();
}
项目:javaide
文件:ConsoleEditText.java
public CharSequence updateStr(CharSequence oldChars, int startPos, CharSequence newChars) {
if (startPos < mLength) {
return oldChars; //don't edit
} else {//if (startPos >= mLength)
SpannableString spannableString = new SpannableString(newChars);
spannableString.setSpan(new ForegroundColorSpan(Color.GREEN), 0,
spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannableString;
}
}
项目:GitHub
文件:PiePolylineChartActivity.java
private SpannableString generateCenterSpannableText() {
SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
s.setSpan(new RelativeSizeSpan(1.5f), 0, 14, 0);
s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
s.setSpan(new RelativeSizeSpan(.65f), 14, s.length() - 15, 0);
s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
return s;
}
项目:GitHub
文件:HalfPieChartActivity.java
private SpannableString generateCenterSpannableText() {
SpannableString s = new SpannableString("MPAndroidChart\ndeveloped by Philipp Jahoda");
s.setSpan(new RelativeSizeSpan(1.7f), 0, 14, 0);
s.setSpan(new StyleSpan(Typeface.NORMAL), 14, s.length() - 15, 0);
s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, s.length() - 15, 0);
s.setSpan(new RelativeSizeSpan(.8f), 14, s.length() - 15, 0);
s.setSpan(new StyleSpan(Typeface.ITALIC), s.length() - 14, s.length(), 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), s.length() - 14, s.length(), 0);
return s;
}
项目:Cable-Android
文件:ContactSelectionListAdapter.java
private CharSequence getSpannedHeaderString(int position) {
final String headerString = getHeaderString(position);
if (isPush(position)) {
SpannableString spannable = new SpannableString(headerString);
spannable.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.signal_primary)), 0, headerString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return spannable;
} else {
return headerString;
}
}
项目:GitHub
文件:PieChartItem.java
private SpannableString generateCenterText() {
SpannableString s = new SpannableString("MPAndroidChart\ncreated by\nPhilipp Jahoda");
s.setSpan(new RelativeSizeSpan(1.6f), 0, 14, 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.VORDIPLOM_COLORS[0]), 0, 14, 0);
s.setSpan(new RelativeSizeSpan(.9f), 14, 25, 0);
s.setSpan(new ForegroundColorSpan(Color.GRAY), 14, 25, 0);
s.setSpan(new RelativeSizeSpan(1.4f), 25, s.length(), 0);
s.setSpan(new ForegroundColorSpan(ColorTemplate.getHoloBlue()), 25, s.length(), 0);
return s;
}
项目:BaseCore
文件:CountDownTimerUtils.java
@Override
public void onTick(long millisUntilFinished) {
mTextView.setClickable(false); //设置不可点击
mTextView.setText(String.format(strFormate, String.valueOf(millisUntilFinished / 1000))); //设置倒计时时间
// mTextView.setBackgroundResource(R.drawable.bg_identify_code_press); //设置按钮为灰色,这时是不能点击的
mTextView.setTextColor(ContextCompat.getColor(mTextView.getContext(), R.color.grey));
/**
* 超链接 URLSpan
* 文字背景颜色 BackgroundColorSpan
* 文字颜色 ForegroundColorSpan
* 字体大小 AbsoluteSizeSpan
* 粗体、斜体 StyleSpan
* 删除线 StrikethroughSpan
* 下划线 UnderlineSpan
* 图片 ImageSpan
* http://blog.csdn.net/ah200614435/article/details/7914459
*/
SpannableString spannableString = new SpannableString(mTextView.getText().toString()); //获取按钮上的文字
ForegroundColorSpan span = new ForegroundColorSpan(Color.RED);
/**
* public void setSpan(Object what, int start, int end, int flags) {
* 主要是start跟end,start是起始位置,无论中英文,都算一个。
* 从0开始计算起。end是结束位置,所以处理的文字,包含开始位置,但不包含结束位置。
*/
spannableString.setSpan(span, 0, 2, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);//将倒计时的时间设置为红色
mTextView.setText(spannableString);
}
项目:GitHub
文件:RecyclerViewAdapterHelper.java
/**
* 处理关键字高亮
* 如果需要检索算法库,请联系我
*
* @param originStr 被处理字符串
* @param keyWord 关键字
* @param hightLightColor 高亮颜色
* @return CharSequence
*/
public static CharSequence handleKeyWordHighLight
(String originStr, String keyWord, @ColorInt int hightLightColor) {
SpannableString ss = new SpannableString(originStr);
Pattern p = Pattern.compile(keyWord);
Matcher m = p.matcher(ss);
while (m.find()) {
ss.setSpan(new ForegroundColorSpan(hightLightColor), m.start(), m.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
return ss;
}
项目:revolution-irc
文件:SpannableStringHelper.java
public static Object cloneSpan(Object span) {
if (span instanceof ForegroundColorSpan)
return new ForegroundColorSpan(((ForegroundColorSpan) span).getForegroundColor());
if (span instanceof BackgroundColorSpan)
return new BackgroundColorSpan(((BackgroundColorSpan) span).getBackgroundColor());
if (span instanceof StyleSpan)
return new StyleSpan(((StyleSpan) span).getStyle());
return null;
}
项目:UltimateRecyclerView
文件:StickyAdapter.java
private void setData(SuperViewHolder holder, StockEntity.StockInfo item) {
final String stockNameAndCode = item.stock_name + "\n" + item.stock_code;
SpannableStringBuilder ssb = new SpannableStringBuilder(stockNameAndCode);
ssb.setSpan(new ForegroundColorSpan(Color.parseColor("#a4a4a7")), item.stock_name.length(), stockNameAndCode.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.setSpan(new AbsoluteSizeSpan(dip2px(holder.itemView.getContext(), 13)), item.stock_name.length(), stockNameAndCode.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
((TextView) holder.getView(R.id.tv_stock_name_code)).setText(ssb);
((TextView) holder.getView(R.id.tv_current_price)).setText(item.current_price);
((TextView) holder.getView(R.id.tv_rate)).setText(item.rate < 0 ? String.format("%.2f", item.rate) : ("+" + String.format("%.2f", item.rate)) + "%");
}
项目:QMark
文件:EditSourceListAdapter.java
@Override
public void bind(int position, EditSourceListBean data) {
mFB.display(mImgBg, data.imgBgUrl);
mFB.display(mImgCatgy, data.ImgCatgyUrl);
mTextLeft.setText(data.textLeft);
Resources resources = getView().getResources();
SpannableStringBuilder spans = new SpannableStringBuilder(resources.getString(R.string.i_m_category_text_sign_count, data.textSignSize));
spans.setSpan(new ForegroundColorSpan(resources.getColor(R.color.text_title_orange)), 0, 2, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
spans.setSpan(new ForegroundColorSpan(resources.getColor(R.color.text_title_orange)), spans.length() - 3, spans.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
mTextSignSize.setText(spans);
}
项目:reactive-architectures-playground
文件:FactsViewModelMapper.java
private FactViewModel composedWithSpans(FactAboutNumber fact) {
int accent = ContextCompat.getColor(context, R.color.colorAccent);
return ComposedWithSpannedStyles.with(
fact.number,
" " + formatFact(fact.number, fact.fact),
new ForegroundColorSpan(accent)
);
}
项目:GongXianSheng
文件:AbstractStockListFragment.java
@Override
public void onBindViewHolder(ViewHolder viewHolder, int position) {
final StockItem bean = mStockList.get(position);
StockItem.Product productBean = bean.getProduct();
if (productBean != null) {
if (!TextUtils.isEmpty(mKeyword)) {
int index = productBean.getName().indexOf(mKeyword);
if (index != -1) {
SpannableString spannStr = new SpannableString(productBean.getName());
spannStr.setSpan(new ForegroundColorSpan(Color.parseColor("#6bb400")), index, index + mKeyword.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
viewHolder.name.setText(spannStr);
}
} else {
viewHolder.name.setText(productBean.getName());
}
viewHolder.number.setText(productBean.getDefaultCode() + " | ");
viewHolder.content.setText(productBean.getUnit());
if (productBean.getImage() !=null){
FrecoFactory.getInstance(getActivity()).disPlay(viewHolder.sDv, RunwiseService.ENDPOINT + productBean.getImage().getImageSmall());
}
}
viewHolder.value.setText(NumberUtil.getIOrD(String.valueOf(bean.getQty())));
viewHolder.uom.setText(bean.getUom());
if (TextUtils.isEmpty(bean.getLotNum())){
viewHolder.dateNumber.setVisibility(View.INVISIBLE);
}else{
viewHolder.dateNumber.setText(bean.getLotNum());
viewHolder.dateNumber.setVisibility(View.VISIBLE);
}
viewHolder.dateLate.setText(DateFormateUtil.getLaterFormat(bean.getLifeEndDate()));
}
项目:Exoplayer2Radio
文件:Tx3gDecoder.java
private static void attachColor(SpannableStringBuilder cueText, int colorRgba,
int defaultColorRgba, int start, int end, int spanPriority) {
if (colorRgba != defaultColorRgba) {
int colorArgb = ((colorRgba & 0xFF) << 24) | (colorRgba >>> 8);
cueText.setSpan(new ForegroundColorSpan(colorArgb), start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | spanPriority);
}
}