本文整理了Java中android.text.SpannableString.setSpan()
方法的一些代码示例,展示了SpannableString.setSpan()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SpannableString.setSpan()
方法的具体详情如下:
包路径:android.text.SpannableString
类名称:SpannableString
方法名:setSpan
暂无
代码示例来源:origin: stackoverflow.com
String tempString="Copyright";
TextView text=(TextView)findViewById(R.id.text);
SpannableString spanString = new SpannableString(tempString);
spanString.setSpan(new UnderlineSpan(), 0, spanString.length(), 0);
spanString.setSpan(new StyleSpan(Typeface.BOLD), 0, spanString.length(), 0);
spanString.setSpan(new StyleSpan(Typeface.ITALIC), 0, spanString.length(), 0);
text.setText(spanString);
代码示例来源:origin: PhilJay/MPAndroidChart
private SpannableString generateCenterText() {
SpannableString s = new SpannableString("Revenues\nQuarters 2015");
s.setSpan(new RelativeSizeSpan(2f), 0, 8, 0);
s.setSpan(new ForegroundColorSpan(Color.GRAY), 8, s.length(), 0);
return s;
}
}
代码示例来源:origin: stackoverflow.com
TextView tv = (TextView) findViewById(R.id.textview);
SpannableString text = new SpannableString(myString);
text.setSpan(new TextAppearanceSpan(getContext(), R.style.myStyle), 0, 5, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
text.setSpan(new TextAppearanceSpan(getContext(), R.style.myNextStyle), 6, 10, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(text, TextView.BufferType.SPANNABLE);
代码示例来源:origin: stackoverflow.com
String s= "Hello Everyone";
SpannableString ss1= new SpannableString(s);
ss1.setSpan(new RelativeSizeSpan(2f), 0,5, 0); // set size
ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);// set color
TextView tv= (TextView) findViewById(R.id.textview);
tv.setText(ss1);
代码示例来源:origin: wangdan/AisenWeiBo
MyURLSpan[] urlSpans = value.getSpans(0, value.length(), MyURLSpan.class);
int findStart = 0;
int findEnd = 0;
WebURLEmotionSpan[] webURLEmotionSpans = value.getSpans(0, value.length(), WebURLEmotionSpan.class);
findStart = 0;
findEnd = 0;
value.setSpan(webURLEmotionSpan, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
tv.setText(value);
value.setSpan(backgroundColorSpan, findStart, findEnd, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
tv.setText(value);
case MotionEvent.ACTION_CANCEL:
case MotionEvent.ACTION_UP:
WebURLEmotionSpan[] webURLEmotionSpans = value.getSpans(0, value.length(), WebURLEmotionSpan.class);
for (WebURLEmotionSpan webURLEmotionSpan : webURLEmotionSpans) {
int start = value.getSpanStart(webURLEmotionSpan);
value.setSpan(webURLEmotionSpan, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
tv.setText(value);
代码示例来源:origin: stackoverflow.com
SpannableString text = new SpannableString("Lorem ipsum dolor sit amet");
// make "Lorem" (characters 0 to 5) red
text.setSpan(new ForegroundColorSpan(Color.RED), 0, 5, 0);
textView.setText(text, BufferType.SPANNABLE);
代码示例来源:origin: stackoverflow.com
SpannableString spannablecontent=new SpannableString(o.content.toString());
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC),
0,spannablecontent.length(), 0);
// set Text here
tt.setText(spannablecontent);
代码示例来源:origin: stackoverflow.com
TextView textView = (TextView) view.findViewById(R.id.textview);
SpannableString content = new SpannableString("Content");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
textView.setText(content);
代码示例来源:origin: stackoverflow.com
public class TestActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TextView textView = (TextView) findViewById(R.id.textview);
SpannableString ss = new SpannableString("abc");
Drawable d = getResources().getDrawable(R.drawable.icon32);
d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BASELINE);
ss.setSpan(span, 0, 3, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
textView.setText(ss);
}
代码示例来源:origin: stackoverflow.com
public static void clickify(TextView view, final String clickableText,
final ClickSpan.OnClickListener listener) {
CharSequence text = view.getText();
String string = text.toString();
ClickSpan span = new ClickSpan(listener);
int start = string.indexOf(clickableText);
int end = start + clickableText.length();
if (start == -1) return;
if (text instanceof Spannable) {
((Spannable)text).setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
} else {
SpannableString s = SpannableString.valueOf(text);
s.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
view.setText(s);
}
MovementMethod m = view.getMovementMethod();
if ((m == null) || !(m instanceof LinkMovementMethod)) {
view.setMovementMethod(LinkMovementMethod.getInstance());
}
}
代码示例来源:origin: PhilJay/MPAndroidChart
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;
}
代码示例来源:origin: yanzhenjie/NoHttp
public static SpannableString getColorText(CharSequence content, int start, int end, int color) {
SpannableString stringSpan = new SpannableString(content);
stringSpan.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
return stringSpan;
}
代码示例来源:origin: stackoverflow.com
SpannableString spannablecontent=new SpannableString(o.content.toString());
spannablecontent.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC),
0,spannablecontent.length(), 0);
// set Text here
tt.setText(spannablecontent);
代码示例来源:origin: stackoverflow.com
TextView tv = (TextView) view.findViewById(R.id.tv);
SpannableString content = new SpannableString("Content");
content.setSpan(new UnderlineSpan(), 0, content.length(), 0);
tv.setText(content);
代码示例来源:origin: eleme/UETool
private void updateSpanTextView() {
TextView spanTextView = findViewById(R.id.span);
SpannableString spannableString = new SpannableString(" 海底捞火锅");
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_food_new);
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
VerticalImageSpan imageSpan = new VerticalImageSpan(drawable);
spannableString.setSpan(imageSpan, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
spanTextView.setText(spannableString);
}
代码示例来源:origin: stackoverflow.com
tv.setText("Whale and Lion");
} else {
SpannableString s = SpannableString.valueOf(text);
s.setSpan(span, start, end, Spanned.SPAN_MARK_MARK);
view.setText(s);
代码示例来源:origin: PhilJay/MPAndroidChart
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;
}
代码示例来源:origin: stackoverflow.com
String udata="Underlined Text";
SpannableString content = new SpannableString(udata);
content.setSpan(new UnderlineSpan(), 0, udata.length(), 0);
mTextView.setText(content);
代码示例来源:origin: stackoverflow.com
private void applyFontToMenuItem(MenuItem mi) {
Typeface font = Typeface.createFromAsset(getAssets(), "ds_digi_b.TTF");
SpannableString mNewTitle = new SpannableString(mi.getTitle());
mNewTitle.setSpan(new CustomTypefaceSpan("" , font), 0 , mNewTitle.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
mi.setTitle(mNewTitle);
}
代码示例来源:origin: smuyyh/BookReader
@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", ""));
}
}
}
内容来源于网络,如有侵权,请联系作者删除!