/** * Update {@link #spanned} according to the give charSequence and styles * @param text the give raw text. * @return an Spanned contains text and spans */ private @NonNull Spanned createSpanned(String text) { if (!TextUtils.isEmpty(text)) { SpannableString spannable = new SpannableString(text); List<SetSpanOperation> ops = createSetSpanOperation(spannable.length()); if (mFontSize == UNSET) { ops.add(new SetSpanOperation(0, spannable.length(), new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE))); } Collections.reverse(ops); for (SetSpanOperation op : ops) { op.execute(spannable); } return spannable; } return new SpannableString(""); }
private void drawFollowNum(long num) { LogInfo.log("clf", "drawFollowNum....num=" + num); String followNum = StringUtils.getPlayCountsToStr(num); if (TextUtils.isEmpty(followNum)) { this.mFollowNum.setText("0"); return; } String unit = ""; String lastChar = followNum.substring(followNum.length() - 1); if (!StringUtils.isInt(lastChar)) { unit = " " + lastChar; followNum = followNum.substring(0, followNum.length() - 1) + unit; } int start = followNum.length() - unit.length(); int end = followNum.length(); SpannableStringBuilder sb = new SpannableStringBuilder(followNum); sb.setSpan(new StyleSpan(1), 0, start, 33); sb.setSpan(new AbsoluteSizeSpan(getResources().getDimensionPixelSize(2131165476)), start, end, 33); this.mFollowNum.setText(sb); }
/** * 设置字体大小 * @param textSize textSize */ void setTextSize(int textSize) { Editable edit = getEditableText(); int index = getSelectionIndex(); int star = getSectionStart(); int end = getSectionEnd(); if (star >= end) return; if (index >= 0 && index < mSections.size()) { TextSection section = mSections.get(index); section.setTextSize(textSize); if (mListener != null) { mListener.onSectionChange(section); } } AbsoluteSizeSpan[] styleSpans = edit.getSpans(star, end, AbsoluteSizeSpan.class); for (AbsoluteSizeSpan span : styleSpans) { edit.removeSpan(span); } edit.setSpan(new AbsoluteSizeSpan(UI.dipToPx(getContext(), textSize)), star, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); update(index); }
private void endCssStyle(String tag, Editable text) { Strikethrough s = getLast(text, Strikethrough.class); if (s != null) { setSpanFromMark(tag, text, s, new StrikethroughSpan()); } Background b = getLast(text, Background.class); if (b != null) { setSpanFromMark(tag, text, b, new BackgroundColorSpan(b.mBackgroundColor)); } Foreground f = getLast(text, Foreground.class); if (f != null) { setSpanFromMark(tag, text, f, new ForegroundColorSpan(f.mForegroundColor)); } AbsoluteSize a = getLast(text, AbsoluteSize.class); if (a != null) { setSpanFromMark(tag, text, a, new AbsoluteSizeSpan(a.getTextSize())); } RelativeSize r = getLast(text, RelativeSize.class); if (r != null) { setSpanFromMark(tag, text, r, new RelativeSizeSpan(r.getTextProportion())); } }
public Spannable[] itemsToColoredText() { // TODO(hal): Generalize this so that different items could have different // colors and even fonts and sizes int size = items.size(); int displayTextSize = textSize; Spannable [] objects = new Spannable[size]; for (int i = 1; i <= size; i++) { // Note that the ListPicker and otherPickers pickers convert Yail lists to string by calling // YailList.ToStringArray. // ListView however, does the string conversion via the adapter, so we must ensure // that the adapter uses YailListElementToSring String itemString = YailList.YailListElementToString(items.get(i)); // Is there a more efficient way to do conversion to spannable strings that does not // need to allocate new objects? Spannable chars = new SpannableString(itemString); chars.setSpan(new ForegroundColorSpan(textColor),0,chars.length(),0); if (!container.$form().getCompatibilityMode()) { displayTextSize = (int) (textSize * container.$form().deviceDensity()); } chars.setSpan(new AbsoluteSizeSpan(displayTextSize),0,chars.length(),0); objects[i - 1] = chars; } return objects; }
private void handleEndTag(CharacterStyle style) { if (style instanceof URLSpan) { mOut.append("</a>"); } else if (style instanceof TypefaceSpan) { mOut.append("</font>"); } else if (style instanceof ForegroundColorSpan) { mOut.append("</font>"); } else if (style instanceof BackgroundColorSpan) { mOut.append("</font>"); } else if (style instanceof AbsoluteSizeSpan) { mOut.append("</font>"); } else if (style instanceof StrikethroughSpan) { mOut.append("</strike>"); } else if (style instanceof SubscriptSpan) { mOut.append("</sub>"); } else if (style instanceof SuperscriptSpan) { mOut.append("</sup>"); } else if (style instanceof UnderlineSpan) { mOut.append("</u>"); } else if (style instanceof BoldSpan) { mOut.append("</b>"); } else if (style instanceof ItalicSpan) { mOut.append("</i>"); } }
/** * 创建{文字内容、字体颜色、字体大小}分段文字集合体 * * @param text * @param color * @param textSize * @return */ public static SpannableStringBuilder creSpanString(String[] text, int[] color, int[] textSize) { if (text == null || color == null || textSize == null) throw new IllegalArgumentException("参数不能为空"); if (text.length != color.length || text.length != textSize.length) throw new IllegalArgumentException("参数数组长度不一致"); SpannableStringBuilder sb = new SpannableStringBuilder(); try { for (int i = 0; i < text.length; i++) { SpannableString sp = new SpannableString(text[i]); sp.setSpan(new ForegroundColorSpan(color[i]), 0, sp.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); sp.setSpan(new AbsoluteSizeSpan(textSize[i], true), 0, sp.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); sb.append(sp); } return sb; } catch (Exception e) { e.printStackTrace(); } return sb; }
@Override protected void convert(BaseViewHolder holder, StockEntity.StockInfo item) { switch (holder.getItemViewType()) { case StockEntity.StockInfo.TYPE_HEADER: holder.setText(R.id.tv_stock_name, item.pinnedHeaderName).addOnClickListener(R.id.checkbox).setChecked(R.id.checkbox, item.check); break; case StockEntity.StockInfo.TYPE_DATA: final String stockNameAndCode = item.stock_name + "\n" + item.stock_code; SpannableStringBuilder ssb = new SpannableStringBuilder(stockNameAndCode); ssb.setSpan(new ForegroundColorSpan(Color.parseColor("#a4a4a7")), item.stock_name.length(), stockNameAndCode.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ssb.setSpan(new AbsoluteSizeSpan(StockActivity.dip2px(holder.itemView.getContext(), 13)), item.stock_name.length(), stockNameAndCode.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); holder.setText(R.id.tv_stock_name_code, ssb).setText(R.id.tv_current_price, item.current_price) .setText(R.id.tv_rate, (item.rate < 0 ? String.format("%.2f", item.rate) : "+" + String.format("%.2f", item.rate)) + "%"); break; } }
private void setTimeDay(TextView textView, String day) { final Resources resources = textView.getResources(); final String suffix = resources.getString(R.string.txt_day); final int dayLen = day.length(); SpannableStringBuilder sBuilder = new SpannableStringBuilder(); sBuilder.append(day) // Bold this .append('\n') // Default TextView font. .append(suffix); // Default TextView font. // Create the Typeface you want to apply to certain text CalligraphyTypefaceSpan typefaceSpan = new CalligraphyTypefaceSpan(TypefaceUtils.load(resources.getAssets(), "fonts/Hero.otf")); sBuilder.setSpan(typefaceSpan, 0, dayLen, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // Font sBuilder.setSpan(new AbsoluteSizeSpan(resources.getDimensionPixelSize(R.dimen.font_24)), 0, dayLen, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // Color sBuilder.setSpan(new ForegroundColorSpan(resources.getColor(R.color.cyan_700)), 0, dayLen, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(sBuilder, TextView.BufferType.SPANNABLE); }
/** * Update {@link #spannableStringBuilder} according to the give charSequence and {@link #style} * @param text the give raw text. * @return an editable contains text and spans */ private Editable updateSpannableStringBuilder(String text) { spannableStringBuilder.clear(); if (text != null) { spannableStringBuilder.append(text); } List<SetSpanOperation> ops = createSetSpanOperation(spannableStringBuilder.length()); if (mFontSize == UNSET) { spannableStringBuilder.setSpan( new AbsoluteSizeSpan(WXText.sDEFAULT_SIZE), 0, spannableStringBuilder .length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); } Collections.reverse(ops); for (SetSpanOperation op : ops) { op.execute(spannableStringBuilder); } return spannableStringBuilder; }
/** * 现金券显示价格样式 */ public static SpannableString getCashPrice(Context context, double oldPrice, double newPrice) { StringBuilder builder = new StringBuilder(); builder.append(handleDouble(newPrice)).append("元").append(" ").append(handleDouble(oldPrice)).append("元"); int start = 0; int middle = builder.indexOf(" ") + 1; int end = builder.length(); SpannableString string = new SpannableString(builder); /*改变文字的大小*/ string.setSpan(new AbsoluteSizeSpan(sp2px(context, 20)), start, middle, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); string.setSpan(new AbsoluteSizeSpan(sp2px(context, 14)), middle, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); /*给文字设置删除线*/ string.setSpan(new StrikethroughSpan(), middle, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); /*改变文字的颜色*/ int textOrange = context.getResources().getColor(android.R.color.holo_red_light); int textGray = context.getResources().getColor(android.R.color.darker_gray); string.setSpan(new ForegroundColorSpan(textOrange), start, middle, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); string.setSpan(new ForegroundColorSpan(textGray), middle, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return string; }
public Spannable build() { SpannableStringBuilder textSpan = new SpannableStringBuilder(); int start = 0; int end = 0; for (int i = 0; i < list.size(); i++) { SpanWrapper wrapper = list.get(i); String text = wrapper.getText(); start = end; end = end + text.length(); textSpan.append(text); AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan(getContext().getResources().getDimensionPixelSize(wrapper.getTextSize())); ForegroundColorSpan colorSpan = new ForegroundColorSpan(getContext().getResources().getColor(wrapper.getTextColor())); textSpan.setSpan(sizeSpan, start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE); textSpan.setSpan(colorSpan, start, end, Spannable.SPAN_INCLUSIVE_INCLUSIVE); } return textSpan; }
private void about() { // 先移除所有的動態view linearLayout.removeView(recycle); linearLayout.removeView(recycle2); linearLayout.removeView(recycle3); linearLayout.removeView(about); linearLayout.removeView(explan); /* TODO 關於我們 * * */ String text = "\n\n\n開發成員 : \n\n陳亮宇\n張弘瑜\n鍾羽函\n蘇柏丞\n謝宣緯\n\n\n\n\t資料來源 : 行政院文化局"; SpannableString spannable = new SpannableString(text); spannable.setSpan(new AbsoluteSizeSpan(80), 0, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); spannable.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(Color.parseColor("#FF533210")), 0, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); spannable.setSpan(new AbsoluteSizeSpan(100), 3, 7, Spanned.SPAN_EXCLUSIVE_INCLUSIVE); spannable.setSpan(new AbsoluteSizeSpan(100), 36, 40, Spanned.SPAN_EXCLUSIVE_INCLUSIVE); about.setText(spannable); linearLayout.addView(about); }
private void info() { // 先移除所有的動態view linearLayout.removeView(recycle); linearLayout.removeView(recycle2); linearLayout.removeView(recycle3); linearLayout.removeView(about); linearLayout.removeView(explan); /* TODO 說明 * * */ String text = "\n\n\n 這是一個彙整台灣獨立書店的app,資料取自文化局的開放資源,主要目的在於提供沒接觸過或是剛接觸獨立書店的民眾,可以找尋到自己生活周遭哪裡有獨立書店,該如何拜訪、參觀,並且了解各個獨立店家的特色"; SpannableString spannable = new SpannableString(text); spannable.setSpan(new AbsoluteSizeSpan(80), 0, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); spannable.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_NORMAL), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(Color.parseColor("#FF533210")), 0, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); explan.setText(spannable); linearLayout.addView(explan); }
@Override public void onBindViewHolder(MovieHolder holder, final int position) { String movieName = list.get(position).getMovieName(); String briefIntro = list.get(position).getBriefIntro(); String content = movieName + "\n\n" + briefIntro; SpannableStringBuilder style = new SpannableStringBuilder(content); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(20)), 0, movieName.length(), SPAN_INCLUSIVE_INCLUSIVE); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(14)), movieName.length() + 2, content.length () - 1, SPAN_INCLUSIVE_INCLUSIVE); holder.mTvContent.setText(style); GlideUtil.setImage(mContext, list.get(position).getPic(), holder.mIvMovie); holder.mCvMovie.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (listener != null) { listener.click(list.get(position)); } } }); }
@Override public void showArticle(ArticleOne article) { String title = article.getArticleTitle(); String author = article.getArticleAuthor(); String content = article.getArticleContent(); String text = title + "\n" + author + "\n\n" + content; SpannableStringBuilder style = new SpannableStringBuilder(text); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(30)), 0, title.length(), Spanned .SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(20)), title.length() + 1, title .length() + 1 + author.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, title .length() + 1 + author.length(), Spanned .SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(16)), title.length() + author .length() + 3, text.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); mTvContent.setText(style); }
@Override public void showContent(Movie movie) { String movieName = movie.getMovieName(); String country = movie.getCountry(); String briefIntro = movie.getBriefIntro(); String content = movieName + "\n" + country + "\n" + briefIntro; SpannableStringBuilder style = new SpannableStringBuilder(content); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(30)), 0, movieName.length(), Spanned .SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(20)), movieName.length() + 1, movieName .length() + 1 + country.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AlignmentSpan.Standard(Layout.Alignment.ALIGN_CENTER), 0, movieName .length() + 1 + country.length(), Spanned .SPAN_EXCLUSIVE_INCLUSIVE); style.setSpan(new AbsoluteSizeSpan(SystemUtil.dp2px(16)), movieName.length() + country .length() + 3, content.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE); mTvMovieContent.setText(style); }
@Override protected void onPostExecute(Total result) { if (isRunning) { if (BudgetListFragment.this.getActivity()!=null) { Utils u = new Utils(BudgetListFragment.this.getActivity()); if (adapter!=null && totalText!=null) { u.setTotal(totalText, result); SpannableString spannablecontent=new SpannableString(totalText.getText()); spannablecontent.setSpan(new AbsoluteSizeSpan(20,true), 0, spannablecontent.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); // set Text here totalText.setText(spannablecontent); ((BudgetListAdapter)adapter).notifyDataSetChanged(); } } } }
@Override public CharSequence getPageTitle(int position) { Category category = categoryList.get(position); String title = category.getName(); int fontSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 16, context.getResources().getDisplayMetrics()); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(title); Typeface font = Fonts.getDefaultFont(); ForegroundColorSpan fcs = new ForegroundColorSpan(category.getIntColor()); AbsoluteSizeSpan ass = new AbsoluteSizeSpan(fontSize); StyleSpan bss = new StyleSpan(Typeface.BOLD); spannableStringBuilder.setSpan(new CustomTypefaceSpan(font), 0, title.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE); spannableStringBuilder.setSpan(fcs, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); spannableStringBuilder.setSpan(bss, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); spannableStringBuilder.setSpan(ass, 0, title.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE); return spannableStringBuilder; }
protected void setText() { Typeface roboto = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(), "font/Roboto-Bold.ttf"); Typeface notosans = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(), "font/NotoSans-Regular.ttf"); // title TextView viewTitle = (TextView)mView.findViewById(R.id.title); String strTitle = getString(R.string.sttTitle); SpannableStringBuilder spannable = new SpannableStringBuilder(strTitle); spannable.setSpan(new AbsoluteSizeSpan(47), 0, strTitle.length(), 0); spannable.setSpan(new CustomTypefaceSpan("", roboto), 0, strTitle.length(), 0); viewTitle.setText(spannable); viewTitle.setTextColor(0xFF325C80); // instructions TextView viewInstructions = (TextView)mView.findViewById(R.id.instructions); String strInstructions = getString(R.string.sttInstructions); SpannableString spannable2 = new SpannableString(strInstructions); spannable2.setSpan(new AbsoluteSizeSpan(20), 0, strInstructions.length(), 0); spannable2.setSpan(new CustomTypefaceSpan("", notosans), 0, strInstructions.length(), 0); viewInstructions.setText(spannable2); viewInstructions.setTextColor(0xFF121212); }
protected void setText() { Typeface roboto = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(), "font/Roboto-Bold.ttf"); Typeface notosans = Typeface.createFromAsset(getActivity().getApplicationContext().getAssets(), "font/NotoSans-Regular.ttf"); TextView viewTitle = (TextView)mView.findViewById(R.id.title); String strTitle = getString(R.string.ttsTitle); SpannableString spannable = new SpannableString(strTitle); spannable.setSpan(new AbsoluteSizeSpan(47), 0, strTitle.length(), 0); spannable.setSpan(new CustomTypefaceSpan("", roboto), 0, strTitle.length(), 0); viewTitle.setText(spannable); viewTitle.setTextColor(0xFF325C80); TextView viewInstructions = (TextView)mView.findViewById(R.id.instructions); String strInstructions = getString(R.string.ttsInstructions); SpannableString spannable2 = new SpannableString(strInstructions); spannable2.setSpan(new AbsoluteSizeSpan(20), 0, strInstructions.length(), 0); spannable2.setSpan(new CustomTypefaceSpan("", notosans), 0, strInstructions.length(), 0); viewInstructions.setText(spannable2); viewInstructions.setTextColor(0xFF121212); }
/*** * @param amPmFontSize - size of am/pm label (label removed is size is 0). * @return format string for 12 hours mode time */ public static CharSequence get12ModeFormat(int amPmFontSize) { String skeleton = "hma"; String pattern = DateFormat.getBestDateTimePattern(Locale.getDefault(), skeleton); // Remove the am/pm if (amPmFontSize <= 0) { pattern.replaceAll("a", "").trim(); } // Replace spaces with "Hair Space" pattern = pattern.replaceAll(" ", "\u200A"); // Build a spannable so that the am/pm will be formatted int amPmPos = pattern.indexOf('a'); if (amPmPos == -1) { return pattern; } Spannable sp = new SpannableString(pattern); sp.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), amPmPos, amPmPos + 1, Spannable.SPAN_POINT_MARK); sp.setSpan(new AbsoluteSizeSpan(amPmFontSize), amPmPos, amPmPos + 1, Spannable.SPAN_POINT_MARK); sp.setSpan(new TypefaceSpan("sans-serif-condensed"), amPmPos, amPmPos + 1, Spannable.SPAN_POINT_MARK); return sp; }
Layout createTextLayout(String text) { int textWidth = (int) textPaint.measureText(text); int unitTextSize = (int) (textPaint.getTextSize() / 2); spannableString.clear(); spannableString.clearSpans(); spannableString.append(text); if (textAppearanceSpan != null) { spannableString.setSpan(textAppearanceSpan, 0, text.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } int hrIndex = text.indexOf("h"); int minIndex = text.indexOf("m"); int secIndex = text.indexOf("s"); spannableString.setSpan(new AbsoluteSizeSpan(unitTextSize), hrIndex, hrIndex + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString.setSpan(new AbsoluteSizeSpan(unitTextSize), minIndex, minIndex + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); spannableString.setSpan(new AbsoluteSizeSpan(unitTextSize), secIndex, secIndex + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return new StaticLayout(spannableString, textPaint, textWidth, Layout.Alignment.ALIGN_CENTER, 0, 0, true); }
void setContent(@NonNull List<InnerData> innerDataList) { final Context context = itemView.getContext(); final InnerData header = innerDataList.subList(0, 1).get(0); final List<InnerData> tail = innerDataList.subList(1, innerDataList.size()); mRecyclerView.setLayoutManager(new InnerLayoutManager()); ((InnerAdapter) mRecyclerView.getAdapter()).addData(tail); Glide.with(context) .load(header.avatarUrl) .placeholder(R.drawable.gv_avatar_placeholder) .bitmapTransform(new CropCircleTransformation(context)) .into(mAvatar); final String title1 = header.title + "?"; final Spannable title2 = new SpannableString(header.title + "? - " + header.name); title2.setSpan(new AbsoluteSizeSpan(mTitleSize1), 0, title1.length(), SPAN_INCLUSIVE_INCLUSIVE); title2.setSpan(new AbsoluteSizeSpan(mTitleSize2), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE); title2.setSpan(new ForegroundColorSpan(Color.argb(204, 255, 255, 255)), title1.length(), title2.length(), SPAN_INCLUSIVE_INCLUSIVE); mHeaderCaption1.setText(title1); mHeaderCaption2.setText(title2); mName.setText(String.format("%s %s", header.name, context.getString(R.string.gv_asked))); mInfo.setText(String.format("%s %s · %s", header.age, context.getString(R.string.gv_years), header.address)); }
/** * Create a span section for the sender, and assign the correct font size and weight */ private AbsoluteSizeSpan buildSenderSpan() { int fontSize = (fragment.senderAboveSubject) ? fontSizes.getMessageListSubject(): fontSizes.getMessageListSender(); return new AbsoluteSizeSpan(fontSize, true); }
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources().getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失 }
public Spanned getRating() { String text = item.rating.average + "/" + item.rating.max; Spannable builder = new SpannableStringBuilder(text); int start = text.indexOf('/'); builder.setSpan(new AbsoluteSizeSpan(60), 0, start, Spanned.SPAN_INCLUSIVE_INCLUSIVE); builder.setSpan(new ForegroundColorSpan(getContext().getResources().getColor(R.color.colorPrimary)), 0, start, Spanned.SPAN_INCLUSIVE_INCLUSIVE); return builder; }
@Override public void priceFee(String totalCostStr) { // mFreight_money.setText("RMB:"+totalCostStr); SpannableString styledText = new SpannableString("RMB"+totalCostStr); styledText.setSpan(new AbsoluteSizeSpan(15,true), 0, 4, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); styledText.setSpan(new AbsoluteSizeSpan(20,true), 3, ("RMB"+totalCostStr).length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mFreight_money.setText(styledText, BufferType.SPANNABLE); }
private void initPassHint() { String hintPart1 = mRes.getString(R.string.passwordRegTips); String hintPart2 = mRes.getString(R.string.passwordRegSubTips); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(); SpannableString sPart1 = new SpannableString(hintPart1); SpannableString sPart2 = new SpannableString(hintPart2); AbsoluteSizeSpan span = new AbsoluteSizeSpan(DisplayUtil.dip2px(mAppCtx,12)); sPart2.setSpan(span,0,hintPart2.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE); spannableStringBuilder.append(sPart1).append(sPart2); mPassdEt.setHint(spannableStringBuilder); }
public void bind(BookList item) { Lex.say(R.string.name_template) .with(LexKey.FIRST_NAME, item.firstName) .with(LexKey.LAST_NAME, item.lastName) .into(title); Lex.list(item.titles) .wrappedIn(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC)) .wrappedIn(new ForegroundColorSpan(Color.WHITE)) .separator(R.string.comma_separator) .twoItemSeparator(R.string.and_separator) .lastItemSeparator(R.string.comma_and_separator) .into(description); Lex.say(R.string.item_count_template) .withNumber(LexKey.COUNT, item.titles.length) .wrappedIn(new AbsoluteSizeSpan(24, true)) .wrappedIn(new ForegroundColorSpan(Color.WHITE)) .withPlural(LexKey.ITEM, item.titles.length, R.plurals.book) .wrappedIn(new ForegroundColorSpan(Color.YELLOW)) .into(bookCount); Lex.say(R.string.gpa_template) .withNumber(LexKey.NUMBER, item.gpa, GPA_FORMAT) .wrappedIn(new AbsoluteSizeSpan(24, true)) .into(gpa); }
@Test public void absolute_size_should_add_only_one_span() { spanBuilder.absoluteSize(range, INTEGER_ARG) .apply(); verify((SpanEZ) spanBuilder, times(1)) .addSpan(isA(TargetRange.class), isA(AbsoluteSizeSpan.class)); }
@Test public void absolute_size_pixel_independent_should_add_only_one_span() { spanBuilder.absoluteSizeDP(range, INTEGER_ARG) .apply(); verify((SpanEZ) spanBuilder, times(1)) .addSpan(isA(TargetRange.class), isA(AbsoluteSizeSpan.class)); }
/** * 设置hint大小 * * @param size * @param v * @param res */ public static void setViewHintSize(Context context, int size, TextView v, int res) { SpannableString ss = new SpannableString(getResources(context).getString( res)); // 新建一个属性对象,设置文字的大小 AbsoluteSizeSpan ass = new AbsoluteSizeSpan(size, true); // 附加属性到文本 ss.setSpan(ass, 0, ss.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); // 设置hint v.setHint(new SpannedString(ss)); // 一定要进行转换,否则属性会消失 }