Android使用粗体字符作为部分文本
我想简单地使用Android使用粗体字符作为部分文本,android,Android,我想简单地使用作为部分文本,比如HTML&CSS,我下面的代码不正确 textEdit.setText("<![CDATA[ <b>"+ "bold text" + " </b> ]]>" + " view other normal text" ); textEdit.setText(“+”粗体文本“+”]]>“+”查看其他普通文本”); 使用将子字符串设置为粗体 String completeString = "<your complete
作为部分文本,比如HTML
&CSS
,我下面的代码不正确
textEdit.setText("<![CDATA[ <b>"+ "bold text" + " </b> ]]>" + " view other normal text" );
textEdit.setText(“+”粗体文本“+”]]>“+”查看其他普通文本”);
使用将子字符串设置为粗体
String completeString = "<your complete string here>";
String subString = "<the substring you want in bold>";
SpannableString ss = new SpannableString(completeString);
ClickableSpan clickableSpan = new ClickableSpan() {
@Override
public void onClick(View textView) {
}
@Override
public void updateDrawState(TextPaint ds) {
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setTypeface(Typeface.DEFAULT_BOLD);
ds.setColor(<color that you want>);
}
};
if (completeString.indexOf(subString) > -1)
ss.setSpan(clickableSpan, completeString.indexOf(subString), completeString.indexOf(subString) + subString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
textEdit.setText(ss, TextView.BufferType.SPANNABLE);
String completeString=”“;
字符串子字符串=”;
SpannableString ss=新SpannableString(completeString);
ClickableSpan ClickableSpan=新的ClickableSpan(){
@凌驾
公共void onClick(查看文本视图){
}
@凌驾
public void updateDrawState(TextPaint ds){
super.updateDrawState(ds);
ds.setUnderlineText(false);
ds.setTypeface(Typeface.DEFAULT_BOLD);
ds.setColor();
}
};
if(completeString.indexOf(subString)>-1)
ss.setSpan(可点击SPAN,completeString.indexOf(子字符串),completeString.indexOf(子字符串)+subString.length(),SPAN.SPAN_EXCLUSIVE_EXCLUSIVE);
setText(ss,TextView.BufferType.Spanable);
使用以下代码:-
mTextBox.setText(Html.fromHtml("<b>" + Bold text+ "</b>" + "<br />" +
"<small>" + Small one+ "</small>" + "<br />" +
"<small>" + Small two+ "</small>"));
mTextBox.setText(Html.fromHtml(“+粗体文本+”+“+”)
“+”小的“+”
“+
“+小二+”);