本文整理汇总了Java中android.text.SpannableString.setSpan方法的典型用法代码示例。如果您正苦于以下问题:Java SpannableString.setSpan方法的具体用法?Java SpannableString.setSpan怎么用?Java SpannableString.setSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.text.SpannableString
的用法示例。
在下文中一共展示了SpannableString.setSpan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyLetterSpacing
import android.text.SpannableString; //导入方法依赖的package包/类
/**
* 字距为任何字符串(技术上,一个简单的方法为CharSequence不使用)的TextView
*/
private void applyLetterSpacing() {
if (this == null || this.originalText == null) return;
StringBuilder builder = new StringBuilder();
for(int i = 0; i < originalText.length(); i++) {
String c = ""+ originalText.charAt(i);
builder.append(c.toLowerCase());
if(i+1 < originalText.length()) {
builder.append("\u00A0");
}
}
SpannableString finalText = new SpannableString(builder.toString());
if(builder.toString().length() > 1) {
for(int i = 1; i < builder.toString().length(); i+=2) {
finalText.setSpan(new ScaleXSpan((letterSpacing+1)/10), i, i+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
super.setText(finalText, BufferType.SPANNABLE);
}
示例2: buildActionTitle
import android.text.SpannableString; //导入方法依赖的package包/类
/**
*
*/
protected SpannableString buildActionTitle() {
int dimensionPixelSize = mActionBarActivity.getResources().getDimensionPixelSize(R.dimen.BigTextSize);
int mutIndex = 0;
String format = "%s";
if(isMute) {
format = format + " #";
mutIndex += 2;
}
SpannableString spannableString = new SpannableString(mTitleText);
//EmoticonUtil.getTextFormat(mActionBarActivity, String.format(format, new Object[]{mTitleText}), dimensionPixelSize);
if(isMute) {
if(mMuteIcon == null) {
mMuteIcon = getTitleIconTips(dimensionPixelSize, R.drawable.chat_mute_notify_title_icon);
}
int length = spannableString.length() - mutIndex + 1;
spannableString.setSpan(mMuteIcon, length, length + 1, SpannableStringBuilder.SPAN_POINT_MARK);
}
return spannableString;
}
示例3: applyFacade
import android.text.SpannableString; //导入方法依赖的package包/类
/**
* @param facade apply the facade to us
*/
void applyFacade(DayViewFacade facade) {
this.isDecoratedDisabled = facade.areDaysDisabled();
setEnabled();
setCustomBackground(facade.getBackgroundDrawable());
setSelectionDrawable(facade.getSelectionDrawable());
// Facade has spans
List<DayViewFacade.Span> spans = facade.getSpans();
if (!spans.isEmpty()) {
String label = getLabel();
SpannableString formattedLabel = new SpannableString(getLabel());
for (DayViewFacade.Span span : spans) {
formattedLabel.setSpan(span.span, 0, label.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
setText(formattedLabel);
}
// Reset in case it was customized previously
else {
setText(getLabel());
}
}
示例4: appendPushNotificationState
import android.text.SpannableString; //导入方法依赖的package包/类
private static void appendPushNotificationState(@NonNull Context context,
@NonNull NotificationState notificationState,
@NonNull Cursor cursor)
{
PushDatabase.Reader reader = null;
SignalServiceEnvelope envelope;
try {
reader = DatabaseFactory.getPushDatabase(context).readerFor(cursor);
while ((envelope = reader.getNext()) != null) {
Recipients recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
Recipient recipient = recipients.getPrimaryRecipient();
long threadId = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
SpannableString body = new SpannableString(context.getString(R.string.MessageNotifier_locked_message));
body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
if (!recipients.isMuted()) {
notificationState.addNotification(new NotificationItem(recipient, recipients, null, threadId, body, 0, null));
}
}
} finally {
if (reader != null)
reader.close();
}
}
示例5: bind
import android.text.SpannableString; //导入方法依赖的package包/类
public void bind(CommandAliasManager.CommandAlias alias) {
if (alias.syntax == null)
return;
SpannableString str = new SpannableString(alias.name + " " + alias.syntax);
str.setSpan(new ForegroundColorSpan(mSecondaryColor), alias.name.length(), str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
mText.setText(str);
mAlias = alias;
}
示例6: relativeSize
import android.text.SpannableString; //导入方法依赖的package包/类
/**
* RelativeSizeSpan,设置文字相对大小,在TextView原有的文字大小的基础上,相对设置文字大小
*/
private void relativeSize () {
SpannableString string = new SpannableString("设置文字的前景色为淡蓝色");
RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.5f);
string.setSpan(sizeSpan, 9, string.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
bgtext.setText(string);
}
示例7: setClickableSpan
import android.text.SpannableString; //导入方法依赖的package包/类
@NonNull
private SpannableString setClickableSpan(String textStr, int position) {
SpannableString subjectSpanText = new SpannableString(textStr);
subjectSpanText.setSpan(new NameClickable(mListView.getSpanClickListener(), position), 0, subjectSpanText.length(),
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return subjectSpanText;
}
示例8: updateStr
import android.text.SpannableString; //导入方法依赖的package包/类
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;
}
}
示例9: foreground
import android.text.SpannableString; //导入方法依赖的package包/类
/**
* ForegroundColorSpan
*/
private void foreground() {
SpannableString string = new SpannableString("设置文字的前景色为淡蓝色");
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#0099EE"));
string.setSpan(colorSpan, 9, string.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
fgtext.setText(string);
}
示例10: setTextSpannable
import android.text.SpannableString; //导入方法依赖的package包/类
public static SpannableString setTextSpannable(TextView textView, String[] strings, int[] color, final OnItemViewListener listener) {
int start = 0;
int end = 0;
StringBuilder sb = new StringBuilder();
for (String str : strings) {
if (str != null) {
sb.append(str);
}
}
SpannableString spannableString = new SpannableString(sb.toString());
for (int i = 0; i < strings.length; ++i) {
if (strings[i] != null) {
end += strings[i].length();
if (color.length == 1) {
spannableString.setSpan(new ForegroundColorSpan(textView.getResources().getColor(color[0])), start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
} else if (color[i] > 0) {
spannableString.setSpan(new ForegroundColorSpan(textView.getResources().getColor(color[i])), start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
}
if (listener != null) {
final int finalI = i;
ClickableSpan cbs = new ClickableSpan() {
@Override
public void onClick(View view) {
listener.onItemViewClick(null, view, finalI);
}
@Override
public void updateDrawState(TextPaint textPaint) {
textPaint.setUnderlineText(false);
}
};
spannableString.setSpan(cbs, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
}
start += strings[i].length();
}
}
textView.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(spannableString);
return spannableString;
}
示例11: formatUrl
import android.text.SpannableString; //导入方法依赖的package包/类
private CharSequence formatUrl(CharSequence url) {
if (this.mUrlColor == null) {
TypedValue colorValue = new TypedValue();
this.mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
this.mUrlColor = this.mContext.getResources().getColorStateList(colorValue.resourceId);
}
SpannableString text = new SpannableString(url);
text.setSpan(new TextAppearanceSpan(null, 0, 0, this.mUrlColor, null), 0, url.length(), 33);
return text;
}
示例12: insert
import android.text.SpannableString; //导入方法依赖的package包/类
@Override
public void insert(SpannableString message) {
final Matcher matcher = getLinkParser(message.toString());
while (matcher.find()) {
final CustomLinkSpan customLinkSpan = new CustomLinkSpan(context, matcher.group());
message.setSpan(customLinkSpan, matcher.start(), matcher.end(), 0);
}
}
示例13: initUI
import android.text.SpannableString; //导入方法依赖的package包/类
@Override
public void initUI() {
SpannableStringBuilder ssb = new SpannableStringBuilder();
//系统通知图片
ImageSpan imageSpan = new ImageSpan(context,R.drawable.img_dm_xttz);
SpannableString spannableString = new SpannableString("tips");
spannableString.setSpan(imageSpan,0,spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
ssb.append(spannableString);
//系统通知内容
ssb.append(getText(R.string.tips_notice_desc));
tvTips.setText(ssb);
}
示例14: contactToToken
import android.text.SpannableString; //导入方法依赖的package包/类
public static CharSequence contactToToken(Recipient c) {
String name = c.getName();
String number = c.getNumber();
SpannableString s = new SpannableString(RecipientsFormatter.formatNameAndNumber(name, number));
int len = s.length();
if (len == 0) {
return s;
}
s.setSpan(new Annotation("number", c.getNumber()), 0, len,
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return s;
}
示例15: setStartContent
import android.text.SpannableString; //导入方法依赖的package包/类
private void setStartContent(String text){
startContentBuilder.clearSpans();
startContentBuilder.clear();
SpannableString searchStr = new SpannableString(mRes.getString(R.string.search) + ":");
searchStr.setSpan(new ForegroundColorSpan(Color.BLACK),0,searchStr.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
SpannableString startContent = new SpannableString(text);
startContent.setSpan(new ForegroundColorSpan(mRes.getColor(R.color.hitalk_yellow))
,0,startContent.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
startContentBuilder.append(searchStr).append(startContent);
searchStartTv.setText(startContentBuilder);
}