本文整理匯總了Java中android.text.SpannableStringBuilder.setSpan方法的典型用法代碼示例。如果您正苦於以下問題:Java SpannableStringBuilder.setSpan方法的具體用法?Java SpannableStringBuilder.setSpan怎麽用?Java SpannableStringBuilder.setSpan使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.text.SpannableStringBuilder
的用法示例。
在下文中一共展示了SpannableStringBuilder.setSpan方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleEmoticonText
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
* 處理帶表情的文本(顯示表情符號)
*
* @param editText
* @param content
* @param context
*/
public static void handleEmoticonText(EditText editText, String content, Context context) {
SpannableStringBuilder sb = new SpannableStringBuilder(content);
String regex = "\\[(\\S+?)\\]";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(content);
Iterator<Emoticon> iterator;
Emoticon emoticon = null;
while (m.find()) {
iterator = emoticonList.iterator();
String tempText = m.group();
while (iterator.hasNext()) {
emoticon = iterator.next();
if (tempText.equals(emoticon.getContent())) {
//轉換為Span並設置Span的大小
sb.setSpan(new VerticalImageSpan(context,
decodeSampledBitmapFromResource(context.getResources(),
emoticon.getImageUri(), dip2px(context, 16), dip2px(context, 16))),
m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
}
}
}
editText.setText(sb);
editText.setSelection(sb.length());
}
示例2: onUploadSuccess
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private void onUploadSuccess(final QueuedMedia item, Attachment media) {
item.id = media.id;
item.preview.setProgress(-1);
item.readyStage = QueuedMedia.ReadyStage.UPLOADED;
/* Add the upload URL to the text field. Also, keep a reference to the span so if the user
* chooses to remove the media, the URL is also automatically removed. */
item.uploadUrl = new URLSpan(media.textUrl);
int end = 1 + media.textUrl.length();
SpannableStringBuilder builder = new SpannableStringBuilder();
builder.append(' ');
builder.append(media.textUrl);
builder.setSpan(item.uploadUrl, 1, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
int cursorStart = textEditor.getSelectionStart();
int cursorEnd = textEditor.getSelectionEnd();
textEditor.append(builder);
textEditor.setSelection(cursorStart, cursorEnd);
waitForMediaLatch.countDown();
}
示例3: emojify
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@Nullable
@UiThread
Spannable emojify(@Nullable CharSequence text, TextView tv) {
if (text == null) return null;
Matcher matches = EMOJI_RANGE.matcher(text);
SpannableStringBuilder builder = new SpannableStringBuilder(text);
while (matches.find()) {
int codePoint = matches.group().codePointAt(0);
Drawable drawable = getEmojiDrawable(codePoint);
if (drawable != null) {
builder.setSpan(new EmojiSpan(drawable, tv), matches.start(),
matches.end(), SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return builder;
}
示例4: internalUpdate
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@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);
}
開發者ID:ABTSoftware,項目名稱:SciChart.Android.Examples,代碼行數:21,代碼來源:CustomTooltipsWithModifiersFragment.java
示例5: createAndPutChipForUser
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private ChipSpan createAndPutChipForUser(TLRPC.User user) {
LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View textView = lf.inflate(R.layout.group_create_bubble, null);
TextView text = (TextView)textView.findViewById(R.id.bubble_text_view);
String name = UserObject.getUserName(user);
if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
name = PhoneFormat.getInstance().format("+" + user.phone);
}
text.setText(name + ", ");
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
textView.destroyDrawingCache();
final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());
SpannableStringBuilder ssb = new SpannableStringBuilder("");
ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
allSpans.add(span);
selectedContacts.put(user.id, span);
for (ImageSpan sp : allSpans) {
ssb.append("<<");
ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
}
userSelectEditText.setText(ssb);
userSelectEditText.setSelection(ssb.length());
return span;
}
示例6: setColorText
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
* 設置彩色文本
*
* @param tv textview
* @param formatStr 格式化字符串
* @param params 需要變色的字符
* @param colors 需要變換的顏色
*/
public static void setColorText(TextView tv, String formatStr, Object[] params, int[] colors) {
if (StringUtil.isEmpty(formatStr) || params.length != colors.length)
return;
String text = String.format(formatStr, params);
SpannableStringBuilder spannable = new SpannableStringBuilder(text);
Pattern p = Pattern.compile("%[abcdefghosx]");
Matcher m = p.matcher(formatStr);
int i = 0;
int begin = 0;
int end = 0;
while (m.find()) {
begin += m.start() - end;
spannable.setSpan(new ForegroundColorSpan(colors[i]), begin, begin + params[i].toString().length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
begin = begin + params[i].toString().length();
end = m.end();
i++;
}
tv.setText(spannable);
}
示例7: applySpansForTag
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private static void applySpansForTag(StartTag startTag, SpannableStringBuilder spannedText) {
switch(startTag.name) {
case TAG_BOLD:
spannedText.setSpan(new StyleSpan(STYLE_BOLD), startTag.position,
spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return;
case TAG_ITALIC:
spannedText.setSpan(new StyleSpan(STYLE_ITALIC), startTag.position,
spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return;
case TAG_UNDERLINE:
spannedText.setSpan(new UnderlineSpan(), startTag.position,
spannedText.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return;
default:
break;
}
}
示例8: emojifyText
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
* replaces emoji shortcodes in a text with EmojiSpans
* @param text the text containing custom emojis
* @param emojis a list of the custom emojis
* @param textView a reference to the textView the emojis will be shown in
* @return the text with the shortcodes replaced by EmojiSpans
*/
public static Spanned emojifyText(Spanned text, List<Status.Emoji> emojis, final TextView textView) {
if (!emojis.isEmpty()) {
SpannableStringBuilder builder = new SpannableStringBuilder(text);
for (Status.Emoji emoji : emojis) {
CharSequence pattern = new StringBuilder(":").append(emoji.getShortcode()).append(':');
Matcher matcher = Pattern.compile(pattern.toString()).matcher(text);
while (matcher.find()) {
// We keep a span as a Picasso target, because Picasso keeps weak reference to
// the target so an anonymous class would likely be garbage collected.
EmojiSpan span = new EmojiSpan(textView);
builder.setSpan(span, matcher.start(), matcher.end(), 0);
Picasso.with(textView.getContext())
.load(emoji.getUrl())
.into(span);
}
}
return builder;
}
return text;
}
示例9: formatMessage
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private CharSequence formatMessage(Cursor cursor) {
SpannableStringBuilder buf = new SpannableStringBuilder();
/*
String remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM));
if (remoteContact.equals("SELF")) {
remoteContact = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_TO));
buf.append("To: ");
}
*/
String remoteContactFull = cursor.getString(cursor.getColumnIndex(SipMessage.FIELD_FROM_FULL));
CallerInfo callerInfo = CallerInfo.getCallerInfoFromSipUri(mContext, remoteContactFull);
if (callerInfo != null && callerInfo.contactExists) {
buf.append(callerInfo.name);
buf.append(" / ");
buf.append(SipUri.getDisplayedSimpleContact(remoteContactFull));
} else {
buf.append(SipUri.getDisplayedSimpleContact(remoteContactFull));
}
int counter = cursor.getInt(cursor.getColumnIndex("counter"));
if (counter > 1) {
buf.append(" (" + counter + ") ");
}
int read = cursor.getInt(cursor.getColumnIndex(SipMessage.FIELD_READ));
// Unread messages are shown in bold
if (read == 0) {
buf.setSpan(STYLE_BOLD, 0, buf.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
}
return buf;
}
示例10: buildCounterSpannable
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private Spannable buildCounterSpannable(String label, int value) {
SpannableStringBuilder contentString = new SpannableStringBuilder();
contentString.append(String.valueOf(value));
contentString.append("\n");
int start = contentString.length();
contentString.append(label);
contentString.setSpan(new TextAppearanceSpan(this, R.style.TextAppearance_Second_Light), start, contentString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return contentString;
}
示例11: createAndPutChipForUser
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private ChipSpan createAndPutChipForUser(TLRPC.User user) {
LayoutInflater lf = (LayoutInflater) ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
View textView = lf.inflate(R.layout.group_create_bubble, null);
TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
String name = UserObject.getUserName(user);
if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
name = PhoneFormat.getInstance().format("+" + user.phone);
}
text.setText(name + ", ");
int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
textView.measure(spec, spec);
textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
Bitmap b = Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(b);
canvas.translate(-textView.getScrollX(), -textView.getScrollY());
textView.draw(canvas);
textView.setDrawingCacheEnabled(true);
Bitmap cacheBmp = textView.getDrawingCache();
Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
textView.destroyDrawingCache();
final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());
SpannableStringBuilder ssb = new SpannableStringBuilder("");
ChipSpan span = new ChipSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
allSpans.add(span);
selectedContacts.put(user.id, span);
for (ImageSpan sp : allSpans) {
ssb.append("<<");
ssb.setSpan(sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
}
userSelectEditText.setText(ssb);
userSelectEditText.setSelection(ssb.length());
return span;
}
示例12: attachFontFamily
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@SuppressWarnings("ReferenceEquality")
private static void attachFontFamily(SpannableStringBuilder cueText, String fontFamily,
String defaultFontFamily, int start, int end, int spanPriority) {
if (fontFamily != defaultFontFamily) {
cueText.setSpan(new TypefaceSpan(fontFamily), start, end,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | spanPriority);
}
}
示例13: getUrlTextSpannableString
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private static SpannableStringBuilder getUrlTextSpannableString(Context context, String source,
int size) {
SpannableStringBuilder builder = new SpannableStringBuilder(source);
String prefix = " ";
builder.replace(0, prefix.length(), prefix);
Drawable drawable = context.getResources().getDrawable(R.mipmap.ic_status_link);
drawable.setBounds(0, 0, size, size);
builder.setSpan(new VerticalImageSpan(drawable), prefix.length(), source.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
builder.append(App.getInstance().getString(R.string.text_url_link));
return builder;
}
示例14: performApplySpans
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@Override
protected void performApplySpans(
SpannableStringBuilder builder,
int begin,
int end,
boolean isEditable) {
mInlineImageSpan.freeze();
builder.setSpan(
mInlineImageSpan,
begin,
end,
Spanned.SPAN_INCLUSIVE_EXCLUSIVE);
}
示例15: setAmountTextWithTwoAmounts
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private void setAmountTextWithTwoAmounts(TextView textView, Currency c, long amount1, long amount2) {
SpannableStringBuilder sb = new SpannableStringBuilder();
sb.append(Utils.amountToString(c, amount1, false));
int x = sb.length();
sb.setSpan(getAmountSpan(context, amount1), 0, x, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
sb.append(" | ");
sb.append(Utils.amountToString(c, amount2, false));
sb.setSpan(getAmountSpan(context, amount2), x+3, sb.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(sb, TextView.BufferType.NORMAL);
}