本文整理匯總了Java中android.text.SpannableStringBuilder.append方法的典型用法代碼示例。如果您正苦於以下問題:Java SpannableStringBuilder.append方法的具體用法?Java SpannableStringBuilder.append怎麽用?Java SpannableStringBuilder.append使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.text.SpannableStringBuilder
的用法示例。
在下文中一共展示了SpannableStringBuilder.append方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getSpannablePriceText
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
* Set string with spannable.
*
* @return: string with two different color
*/
public static SpannableStringBuilder getSpannablePriceText(Context context, String text) {
String[] result = text.split(":");
String first = result[0];
String second = result[1];
first = first.concat(":");
Typeface font = Typeface.createFromAsset(context.getAssets(), "fonts/GILROY-SEMIBOLD.OTF");
SpannableStringBuilder builder = new SpannableStringBuilder();
SpannableString dkgraySpannable = new SpannableString(first + "");
builder.append(dkgraySpannable);
SpannableString blackSpannable = new SpannableString(second);
// blackSpannable.setSpan(new CustomTypefaceSpan("", font), 0, second.length(), 0);
builder.append(blackSpannable);
return builder;
}
示例2: build
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
* Create a spanned string that contains RoundedCornersBackgroundSpan.
*
* @return spanned string
*/
public Spannable build() {
if (mTextParts.isEmpty()) {
throw new IllegalArgumentException("You must specify at least one text part.");
}
boolean first = true;
final SpannableStringBuilder builder = new SpannableStringBuilder();
mSeparatorWidth = 2 * mPadding + mPartsSpacing;
for (final Pair<CharSequence, BackgroundHolder> stringPart : mTextParts) {
if (first) {
first = false;
} else {
final int start = builder.length();
builder.append(" ");
final SpacingSpan spacingSpan = SpacingSpan.newInstance(mSeparatorWidth);
builder.setSpan(spacingSpan, start, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
stringPart.second.setStart(builder.length());
builder.append(stringPart.first);
stringPart.second.setEnd(builder.length());
}
final RoundedCornersBackgroundSpan span = new RoundedCornersBackgroundSpan(this);
builder.setSpan(span, 0, builder.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
return builder;
}
示例3: toFriendly
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
public static CharSequence toFriendly(Address[] addresses, Contacts contacts) {
if (addresses == null) {
return null;
}
if (addresses.length >= TOO_MANY_ADDRESSES) {
// Don't look up contacts if the number of addresses is very high.
contacts = null;
}
SpannableStringBuilder sb = new SpannableStringBuilder();
for (int i = 0; i < addresses.length; i++) {
sb.append(toFriendly(addresses[i], contacts));
if (i < addresses.length - 1) {
sb.append(',');
}
}
return sb;
}
示例4: getMessagePreview
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private CharSequence getMessagePreview(LocalMessage message) {
String subject = message.getSubject();
String snippet = getPreview(message);
boolean isSubjectEmpty = TextUtils.isEmpty(subject);
boolean isSnippetPresent = snippet != null;
if (isSubjectEmpty && isSnippetPresent) {
return snippet;
}
String displaySubject = getMessageSubject(message);
SpannableStringBuilder preview = new SpannableStringBuilder();
preview.append(displaySubject);
if (isSnippetPresent) {
preview.append('\n');
preview.append(snippet);
}
return preview;
}
示例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: makeTwoItems
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@NonNull
private CharSequence makeTwoItems() {
CharSequence s;
if (twoItemSeparator != null) {
s = twoItemSeparator;
} else if (separator != null) {
s = separator;
} else {
throw new LexNoSeparatorException();
}
SpannableStringBuilder sb = new SpannableStringBuilder(getWrappedItem(0));
sb.append(s);
sb.append(getWrappedItem(1));
return sb;
}
示例7: replaceWithLink
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
public CharSequence replaceWithLink(CharSequence source, String param, ArrayList<Integer> uids, AbstractMap<Integer, TLRPC.User> usersDict) {
int start = TextUtils.indexOf(source, param);
if (start >= 0) {
SpannableStringBuilder names = new SpannableStringBuilder("");
for (int a = 0; a < uids.size(); a++) {
TLRPC.User user = null;
if (usersDict != null) {
user = usersDict.get(uids.get(a));
}
if (user == null) {
user = MessagesController.getInstance().getUser(uids.get(a));
}
if (user != null) {
String name = UserObject.getUserName(user);
start = names.length();
if (names.length() != 0) {
names.append(", ");
}
names.append(name);
names.setSpan(new URLSpanNoUnderlineBold("" + user.id), start, start + name.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
}
return TextUtils.replace(source, new String[]{param}, new CharSequence[]{names});
}
return source;
}
示例8: getSpannableString
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
* Set string with spannable.
*
* @param first: string
* @param second: string
* @return: string with two different color
*/
public static SpannableStringBuilder getSpannableString(Context context, String first, String second) {
Typeface font1 = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Regular.ttf");
Typeface font2 = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Medium.ttf");
SpannableStringBuilder builder = new SpannableStringBuilder();
SpannableString dkgraySpannable = new SpannableString(first + " ");
dkgraySpannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mActivity, R.color.primary_text)), 0, first.length(), 0);
dkgraySpannable.setSpan(new CustomTypefaceSpan("", font1), 0, second.length(), 0);
builder.append(dkgraySpannable);
SpannableString blackSpannable = new SpannableString(second);
blackSpannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mActivity, R.color.font_white)), 0, second.length(), 0);
blackSpannable.setSpan(new CustomTypefaceSpan("", font2), 0, second.length(), 0);
builder.append(blackSpannable);
return builder;
}
示例9: cellForRowAtIndexPath
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
public ATableViewCell cellForRowAtIndexPath(ATableView tableView,
NSIndexPath indexPath) {
ATableViewCell cell = super.cellForRowAtIndexPath(tableView,
indexPath);
if (isContentOpen) {
// cell.getTextLabel().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
return cell;
}
SpannableStringBuilder builder = new SpannableStringBuilder();
for (HH2SectionData sec : data) {
for (DataItem item : sec.getData()) {
builder.append(Helper.renderText(String.format("$u{%s},",
item.getYaoList().get(0))));
}
}
linksString = builder;
cell.getTextLabel().setText(builder);
// cell.getTextLabel().setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
return cell;
}
示例10: getSpannableSensorText
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
/**
* Set string with spannable.
*
* @return: string with two different color
*/
public static SpannableStringBuilder getSpannableSensorText(Context context, String text) {
String[] result = text.split("\n\n");
String first = result[0];
String second = result[1];
Typeface font1 = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-LightItalic.ttf");
Typeface font2 = Typeface.createFromAsset(context.getAssets(), "fonts/Roboto-Medium.ttf");
SpannableStringBuilder builder = new SpannableStringBuilder();
SpannableString dkgraySpannable = new SpannableString(first+"\n\n" + " ");
dkgraySpannable.setSpan(new CustomTypefaceSpan("", font1), 0, second.length(), 0);
builder.append(dkgraySpannable);
SpannableString blackSpannable = new SpannableString(second);
blackSpannable.setSpan(new CustomTypefaceSpan("", font2), 0, second.length(), 0);
builder.append(blackSpannable);
return builder;
}
示例11: makeThreeOrMoreItems
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@NonNull
private CharSequence makeThreeOrMoreItems() {
if (separator == null) {
throw new LexNoSeparatorException();
}
SpannableStringBuilder sb = new SpannableStringBuilder(getWrappedItem(0));
for (int i = 1; i < items.length; i++) {
if (i == items.length - 1 && lastItemSeparator != null) {
sb.append(lastItemSeparator);
} else {
sb.append(separator);
}
sb.append(getWrappedItem(i));
}
return sb;
}
示例12: applyEntity
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private static void applyEntity(String entity, SpannableStringBuilder spannedText) {
switch (entity) {
case ENTITY_LESS_THAN:
spannedText.append('<');
break;
case ENTITY_GREATER_THAN:
spannedText.append('>');
break;
case ENTITY_NON_BREAK_SPACE:
spannedText.append(' ');
break;
case ENTITY_AMPERSAND:
spannedText.append('&');
break;
default:
Log.w(TAG, "ignoring unsupported entity: '&" + entity + ";'");
break;
}
}
示例13: beforeChildren
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@Override
public void beforeChildren(TagNode node, SpannableStringBuilder builder, SpanStack spanStack) {
Style useStyle = spanStack.getStyle( node, getStyle() );
if (builder.length() > 0 && useStyle.getDisplayStyle() == Style.DisplayStyle.BLOCK ) {
if ( builder.charAt(builder.length() -1) != '\n' ) {
builder.append('\n');
}
}
//If we have a top margin, we insert an extra newline. We'll manipulate the line height
//of this newline to create the margin.
if ( useStyle.getMarginTop() != null ) {
StyleValue styleValue = useStyle.getMarginTop();
if ( styleValue.getUnit() == StyleValue.Unit.PX ) {
if ( styleValue.getIntValue() > 0 ) {
if ( appendNewLine(builder) ) {
spanStack.pushSpan( new VerticalMarginSpan( styleValue.getIntValue() ),
builder.length() -1, builder.length() );
}
}
} else {
if ( styleValue.getFloatValue() > 0f ) {
if ( appendNewLine(builder) ) {
spanStack.pushSpan( new VerticalMarginSpan( styleValue.getFloatValue() ),
builder.length() -1, builder.length() );
}
}
}
}
}
示例14: convertOptionToString
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
private CharSequence convertOptionToString(PaymentOption item, boolean useBoldLabel) {
SpannableStringBuilder builder = new SpannableStringBuilder(item.getLabel());
if (useBoldLabel) {
builder.setSpan(
new StyleSpan(android.graphics.Typeface.BOLD), 0, builder.length(), 0);
}
if (!TextUtils.isEmpty(item.getSublabel())) {
if (builder.length() > 0) builder.append("\n");
builder.append(item.getSublabel());
}
if (!TextUtils.isEmpty(item.getTertiaryLabel())) {
if (builder.length() > 0) builder.append("\n");
builder.append(item.getTertiaryLabel());
}
if (!item.isComplete() && !TextUtils.isEmpty(item.getEditMessage())) {
if (builder.length() > 0) builder.append("\n");
String editMessage = item.getEditMessage();
builder.append(editMessage);
Object foregroundSpanner = new ForegroundColorSpan(ApiCompatibilityUtils.getColor(
getContext().getResources(), R.color.google_blue_700));
Object sizeSpanner = new AbsoluteSizeSpan(14, true);
int startIndex = builder.length() - editMessage.length();
builder.setSpan(foregroundSpanner, startIndex, builder.length(), 0);
builder.setSpan(sizeSpanner, startIndex, builder.length(), 0);
}
return builder;
}
示例15: beforeChildren
import android.text.SpannableStringBuilder; //導入方法依賴的package包/類
@Override public void beforeChildren(TagNode node, SpannableStringBuilder builder) {
TodoItems todoItem = null;
if (node.getChildTags() != null && node.getChildTags().length > 0) {
for (TagNode tagNode : node.getChildTags()) {
Logger.e(tagNode.getName(), tagNode.getText());
if (tagNode.getName() != null && tagNode.getName().equals("input")) {
todoItem = new TodoItems();
todoItem.isChecked = tagNode.getAttributeByName("checked") != null;
break;
}
}
}
if ("ol".equals(getParentName(node))) {
builder.append(String.valueOf(getMyIndex(node))).append(". ");
} else if ("ul".equals(getParentName(node))) {
if (todoItem != null) {
if (checked == null || unchecked == null) {
builder.append(todoItem.isChecked ? "☑" : "☐");
} else {
builder.append(SpannableBuilder.builder()
.append(todoItem.isChecked ? checked : unchecked))
.append(" ");
}
} else {
builder.append("\u2022 ");
}
}
}