当前位置: 首页>>代码示例>>Java>>正文


Java SpannableString.setSpan方法代码示例

本文整理汇总了Java中android.text.SpannableString.setSpan方法的典型用法代码示例。如果您正苦于以下问题:Java SpannableString.setSpan方法的具体用法?Java SpannableString.setSpan怎么用?Java SpannableString.setSpan使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.text.SpannableString的用法示例。


在下文中一共展示了SpannableString.setSpan方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: applyLetterSpacing

import android.text.SpannableString; //导入方法依赖的package包/类
/**
 * 字距为任何字符串(技术上,一个简单的方法为CharSequence不使用)的TextView
 */
private void applyLetterSpacing() {
    if (this == null || this.originalText == null) return;
    StringBuilder builder = new StringBuilder();
    for(int i = 0; i < originalText.length(); i++) {
        String c = ""+ originalText.charAt(i);
        builder.append(c.toLowerCase());
        if(i+1 < originalText.length()) {
            builder.append("\u00A0");
        }
    }
    SpannableString finalText = new SpannableString(builder.toString());
    if(builder.toString().length() > 1) {
        for(int i = 1; i < builder.toString().length(); i+=2) {
            finalText.setSpan(new ScaleXSpan((letterSpacing+1)/10), i, i+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
    }
    super.setText(finalText, BufferType.SPANNABLE);
}
 
开发者ID:bigjelly,项目名称:AndFast,代码行数:22,代码来源:SpacingTextView.java

示例2: buildActionTitle

import android.text.SpannableString; //导入方法依赖的package包/类
/**
 *
 */
protected SpannableString buildActionTitle() {
    int dimensionPixelSize = mActionBarActivity.getResources().getDimensionPixelSize(R.dimen.BigTextSize);

    int mutIndex = 0;
    String format = "%s";
    if(isMute) {
        format = format + " #";
        mutIndex += 2;
    }

    SpannableString spannableString = new SpannableString(mTitleText);
    //EmoticonUtil.getTextFormat(mActionBarActivity, String.format(format, new Object[]{mTitleText}), dimensionPixelSize);
    if(isMute) {
        if(mMuteIcon == null) {
            mMuteIcon = getTitleIconTips(dimensionPixelSize, R.drawable.chat_mute_notify_title_icon);
        }
        int length = spannableString.length() - mutIndex + 1;
        spannableString.setSpan(mMuteIcon, length, length + 1, SpannableStringBuilder.SPAN_POINT_MARK);
    }
    return spannableString;
}
 
开发者ID:NewCasino,项目名称:browser,代码行数:25,代码来源:CCPActivityBase.java

示例3: applyFacade

import android.text.SpannableString; //导入方法依赖的package包/类
/**
 * @param facade apply the facade to us
 */
void applyFacade(DayViewFacade facade) {
    this.isDecoratedDisabled = facade.areDaysDisabled();
    setEnabled();

    setCustomBackground(facade.getBackgroundDrawable());
    setSelectionDrawable(facade.getSelectionDrawable());

    // Facade has spans
    List<DayViewFacade.Span> spans = facade.getSpans();
    if (!spans.isEmpty()) {
        String label = getLabel();
        SpannableString formattedLabel = new SpannableString(getLabel());
        for (DayViewFacade.Span span : spans) {
            formattedLabel.setSpan(span.span, 0, label.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        }
        setText(formattedLabel);
    }
    // Reset in case it was customized previously
    else {
        setText(getLabel());
    }
}
 
开发者ID:ptrstovka,项目名称:calendarview2,代码行数:26,代码来源:DayView.java

示例4: appendPushNotificationState

import android.text.SpannableString; //导入方法依赖的package包/类
private static void appendPushNotificationState(@NonNull Context context,
                                                @NonNull NotificationState notificationState,
                                                @NonNull Cursor cursor)
{
  PushDatabase.Reader reader = null;
  SignalServiceEnvelope envelope;

  try {
    reader = DatabaseFactory.getPushDatabase(context).readerFor(cursor);

    while ((envelope = reader.getNext()) != null) {
      Recipients      recipients = RecipientFactory.getRecipientsFromString(context, envelope.getSource(), false);
      Recipient       recipient  = recipients.getPrimaryRecipient();
      long            threadId   = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(recipients);
      SpannableString body       = new SpannableString(context.getString(R.string.MessageNotifier_locked_message));
      body.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, body.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

      if (!recipients.isMuted()) {
        notificationState.addNotification(new NotificationItem(recipient, recipients, null, threadId, body, 0, null));
      }
    }
  } finally {
    if (reader != null)
      reader.close();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:27,代码来源:MessageNotifier.java

示例5: bind

import android.text.SpannableString; //导入方法依赖的package包/类
public void bind(CommandAliasManager.CommandAlias alias) {
    if (alias.syntax == null)
        return;
    SpannableString str = new SpannableString(alias.name + " " + alias.syntax);
    str.setSpan(new ForegroundColorSpan(mSecondaryColor), alias.name.length(), str.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mText.setText(str);
    mAlias = alias;
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:9,代码来源:CommandAliasesAdapter.java

示例6: relativeSize

import android.text.SpannableString; //导入方法依赖的package包/类
/**
 * RelativeSizeSpan,设置文字相对大小,在TextView原有的文字大小的基础上,相对设置文字大小
 */
private void relativeSize () {
    SpannableString string = new SpannableString("设置文字的前景色为淡蓝色");
    RelativeSizeSpan sizeSpan = new RelativeSizeSpan(1.5f);
    string.setSpan(sizeSpan, 9, string.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    bgtext.setText(string);
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:10,代码来源:SpannableStringActivity.java

示例7: setClickableSpan

import android.text.SpannableString; //导入方法依赖的package包/类
@NonNull
private SpannableString setClickableSpan(String textStr, int position) {
    SpannableString subjectSpanText = new SpannableString(textStr);
    subjectSpanText.setSpan(new NameClickable(mListView.getSpanClickListener(), position), 0, subjectSpanText.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return subjectSpanText;
}
 
开发者ID:wp521,项目名称:MyFire,代码行数:8,代码来源:FavortListAdapter.java

示例8: updateStr

import android.text.SpannableString; //导入方法依赖的package包/类
public CharSequence updateStr(CharSequence oldChars, int startPos, CharSequence newChars) {
    if (startPos < mLength) {
        return oldChars; //don't edit

    } else {//if (startPos >= mLength)
        SpannableString spannableString = new SpannableString(newChars);
        spannableString.setSpan(new ForegroundColorSpan(Color.GREEN), 0,
                spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannableString;
    }
}
 
开发者ID:tranleduy2000,项目名称:javaide,代码行数:12,代码来源:ConsoleEditText.java

示例9: foreground

import android.text.SpannableString; //导入方法依赖的package包/类
/**
 * ForegroundColorSpan
 */
private void foreground() {
    SpannableString string = new SpannableString("设置文字的前景色为淡蓝色");
    ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.parseColor("#0099EE"));
    string.setSpan(colorSpan, 9, string.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
    fgtext.setText(string);
}
 
开发者ID:wuhighway,项目名称:DailyStudy,代码行数:10,代码来源:SpannableStringActivity.java

示例10: setTextSpannable

import android.text.SpannableString; //导入方法依赖的package包/类
public static SpannableString setTextSpannable(TextView textView, String[] strings, int[] color, final OnItemViewListener listener) {
    int start = 0;
    int end = 0;
    StringBuilder sb = new StringBuilder();
    for (String str : strings) {
        if (str != null) {
            sb.append(str);
        }
    }
    SpannableString spannableString = new SpannableString(sb.toString());
    for (int i = 0; i < strings.length; ++i) {
        if (strings[i] != null) {
            end += strings[i].length();
            if (color.length == 1) {
                spannableString.setSpan(new ForegroundColorSpan(textView.getResources().getColor(color[0])), start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            } else if (color[i] > 0) {
                spannableString.setSpan(new ForegroundColorSpan(textView.getResources().getColor(color[i])), start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            }
            if (listener != null) {
                final int finalI = i;
                ClickableSpan cbs = new ClickableSpan() {
                    @Override
                    public void onClick(View view) {
                        listener.onItemViewClick(null, view, finalI);
                    }
                    @Override
                    public void updateDrawState(TextPaint textPaint) {
                        textPaint.setUnderlineText(false);
                    }
                };
                spannableString.setSpan(cbs, start, end, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);
            }
            start += strings[i].length();
        }
    }

    textView.setMovementMethod(LinkMovementMethod.getInstance());
    textView.setText(spannableString);
    return spannableString;
}
 
开发者ID:abook23,项目名称:godlibrary,代码行数:41,代码来源:SpannableUtils.java

示例11: formatUrl

import android.text.SpannableString; //导入方法依赖的package包/类
private CharSequence formatUrl(CharSequence url) {
    if (this.mUrlColor == null) {
        TypedValue colorValue = new TypedValue();
        this.mContext.getTheme().resolveAttribute(R.attr.textColorSearchUrl, colorValue, true);
        this.mUrlColor = this.mContext.getResources().getColorStateList(colorValue.resourceId);
    }
    SpannableString text = new SpannableString(url);
    text.setSpan(new TextAppearanceSpan(null, 0, 0, this.mUrlColor, null), 0, url.length(), 33);
    return text;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:11,代码来源:SuggestionsAdapter.java

示例12: insert

import android.text.SpannableString; //导入方法依赖的package包/类
@Override
public void insert(SpannableString message) {
    final Matcher matcher = getLinkParser(message.toString());
    while (matcher.find()) {
        final CustomLinkSpan customLinkSpan = new CustomLinkSpan(context, matcher.group());
        message.setSpan(customLinkSpan, matcher.start(), matcher.end(), 0);
    }
}
 
开发者ID:charafau,项目名称:TurboChat,代码行数:9,代码来源:LinkParser.java

示例13: initUI

import android.text.SpannableString; //导入方法依赖的package包/类
@Override
public void initUI() {


    SpannableStringBuilder ssb = new SpannableStringBuilder();
    //系统通知图片
    ImageSpan imageSpan = new ImageSpan(context,R.drawable.img_dm_xttz);
    SpannableString spannableString = new SpannableString("tips");
    spannableString.setSpan(imageSpan,0,spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    ssb.append(spannableString);
    //系统通知内容
    ssb.append(getText(R.string.tips_notice_desc));
    tvTips.setText(ssb);
}
 
开发者ID:jenly1314,项目名称:KingTV,代码行数:15,代码来源:ChatFragment.java

示例14: contactToToken

import android.text.SpannableString; //导入方法依赖的package包/类
public static CharSequence contactToToken(Recipient c) {
  String name       = c.getName();
  String number     = c.getNumber();
  SpannableString s = new SpannableString(RecipientsFormatter.formatNameAndNumber(name, number));
  int len           = s.length();

  if (len == 0) {
    return s;
  }

  s.setSpan(new Annotation("number", c.getNumber()), 0, len,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

  return s;
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:16,代码来源:RecipientsEditor.java

示例15: setStartContent

import android.text.SpannableString; //导入方法依赖的package包/类
private void setStartContent(String text){
    startContentBuilder.clearSpans();
    startContentBuilder.clear();
    SpannableString searchStr = new SpannableString(mRes.getString(R.string.search) + ":");
    searchStr.setSpan(new ForegroundColorSpan(Color.BLACK),0,searchStr.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    SpannableString startContent = new SpannableString(text);
    startContent.setSpan(new ForegroundColorSpan(mRes.getColor(R.color.hitalk_yellow))
            ,0,startContent.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
    startContentBuilder.append(searchStr).append(startContent);
    searchStartTv.setText(startContentBuilder);
}
 
开发者ID:zuoweitan,项目名称:Hitalk,代码行数:12,代码来源:SearchFriend2Layout.java


注:本文中的android.text.SpannableString.setSpan方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。