本文整理汇总了Java中android.text.style.AbsoluteSizeSpan类的典型用法代码示例。如果您正苦于以下问题:Java AbsoluteSizeSpan类的具体用法?Java AbsoluteSizeSpan怎么用?Java AbsoluteSizeSpan使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AbsoluteSizeSpan类属于android.text.style包,在下文中一共展示了AbsoluteSizeSpan类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSpanned
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
/**
* 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("");
}
示例2: drawFollowNum
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
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);
}
示例3: setTextSize
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
/**
* 设置字体大小
* @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);
}
示例4: endCssStyle
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
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()));
}
}
示例5: itemsToColoredText
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
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;
}
示例6: handleEndTag
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
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>");
}
}
示例7: creSpanString
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
/**
* 创建{文字内容、字体颜色、字体大小}分段文字集合体
*
* @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;
}
示例8: convert
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
@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;
}
}
示例9: setTimeDay
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
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);
}
示例10: updateSpannableStringBuilder
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
/**
* 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;
}
示例11: getCashPrice
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
/**
* 现金券显示价格样式
*/
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;
}
示例12: build
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
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;
}
示例13: about
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
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);
}
示例14: info
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
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);
}
示例15: onBindViewHolder
import android.text.style.AbsoluteSizeSpan; //导入依赖的package包/类
@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));
}
}
});
}