|
@@ -22,15 +22,18 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
*/
|
|
*/
|
|
|
public class SpannableSb {
|
|
public class SpannableSb {
|
|
|
private SpannableStringBuilder ssb = new SpannableStringBuilder();
|
|
private SpannableStringBuilder ssb = new SpannableStringBuilder();
|
|
|
|
|
+ private String appendText;
|
|
|
private int start;
|
|
private int start;
|
|
|
private int end;
|
|
private int end;
|
|
|
|
|
|
|
|
public SpannableSb append(Object object) {
|
|
public SpannableSb append(Object object) {
|
|
|
String text = object.toString();
|
|
String text = object.toString();
|
|
|
if(TextUtils.isEmpty(text)){
|
|
if(TextUtils.isEmpty(text)){
|
|
|
|
|
+ appendText = null;
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
ssb.append(text);
|
|
ssb.append(text);
|
|
|
|
|
+ appendText = text;
|
|
|
start = end;
|
|
start = end;
|
|
|
end += text.length();
|
|
end += text.length();
|
|
|
return this;
|
|
return this;
|
|
@@ -49,6 +52,9 @@ public class SpannableSb {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public SpannableSb setTextSize(@DimenRes int textSize) {
|
|
public SpannableSb setTextSize(@DimenRes int textSize) {
|
|
|
|
|
+ if(appendText == null){//无效添加
|
|
|
|
|
+ return this;
|
|
|
|
|
+ }
|
|
|
//AbsoluteSizeSpan 参数 dip: size单位为px,true;size单位为dip(默认为false)。
|
|
//AbsoluteSizeSpan 参数 dip: size单位为px,true;size单位为dip(默认为false)。
|
|
|
AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(ResourceUtils.getXmlDef(textSize), true);
|
|
AbsoluteSizeSpan absoluteSizeSpan = new AbsoluteSizeSpan(ResourceUtils.getXmlDef(textSize), true);
|
|
|
ssb.setSpan(absoluteSizeSpan, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
|
|
ssb.setSpan(absoluteSizeSpan, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
|
|
@@ -56,18 +62,27 @@ public class SpannableSb {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public SpannableSb setTextColor(String textColor) {
|
|
public SpannableSb setTextColor(String textColor) {
|
|
|
|
|
+ if(appendText == null){//无效添加
|
|
|
|
|
+ return this;
|
|
|
|
|
+ }
|
|
|
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor(textColor));
|
|
ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor(textColor));
|
|
|
ssb.setSpan(colorSpan, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
|
|
ssb.setSpan(colorSpan, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
//设置字体样式: NORMAL正常,BOLD粗体,ITALIC斜体,BOLD_ITALIC粗斜体 如: android.graphics.Typeface.BOLD
|
|
//设置字体样式: NORMAL正常,BOLD粗体,ITALIC斜体,BOLD_ITALIC粗斜体 如: android.graphics.Typeface.BOLD
|
|
|
public SpannableSb setTextStyle(int textStyle) {
|
|
public SpannableSb setTextStyle(int textStyle) {
|
|
|
|
|
+ if(appendText == null){//无效添加
|
|
|
|
|
+ return this;
|
|
|
|
|
+ }
|
|
|
StyleSpan colorSpan = new StyleSpan(textStyle);
|
|
StyleSpan colorSpan = new StyleSpan(textStyle);
|
|
|
ssb.setSpan(colorSpan, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
|
|
ssb.setSpan(colorSpan, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
|
//设置样式
|
|
//设置样式
|
|
|
public SpannableSb setTextSpan(ParcelableSpan span) {
|
|
public SpannableSb setTextSpan(ParcelableSpan span) {
|
|
|
|
|
+ if(appendText == null){//无效添加
|
|
|
|
|
+ return this;
|
|
|
|
|
+ }
|
|
|
ssb.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
|
|
ssb.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
|
|
|
return this;
|
|
return this;
|
|
|
}
|
|
}
|
|
@@ -85,6 +100,7 @@ public class SpannableSb {
|
|
|
public SpannableSb appendDrawable(int drawableId) {
|
|
public SpannableSb appendDrawable(int drawableId) {
|
|
|
String text = "★";
|
|
String text = "★";
|
|
|
ssb.append(text);
|
|
ssb.append(text);
|
|
|
|
|
+ appendText = text;
|
|
|
start = end;
|
|
start = end;
|
|
|
end += text.length();
|
|
end += text.length();
|
|
|
ImageSpan imageSpan = new ImageSpan(SheepApp.getInstance(), drawableId);
|
|
ImageSpan imageSpan = new ImageSpan(SheepApp.getInstance(), drawableId);
|