android.text.SpannableString.toString()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(10.1k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中android.text.SpannableString.toString()方法的一些代码示例,展示了SpannableString.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。SpannableString.toString()方法的具体详情如下:
包路径:android.text.SpannableString
类名称:SpannableString
方法名:toString

SpannableString.toString介绍

暂无

代码示例

代码示例来源:origin: smuyyh/BookReader

public void setText(String text) {
  int startIndex = 0;
  while (true) {
    int start = text.indexOf("《");
    int end = text.indexOf("》");
    if (start < 0 || end < 0) {
      append(text.substring(startIndex));
      break;
    }
    append(text.substring(startIndex, start));
    SpannableString spanableInfo = new SpannableString(text.substring(start, end + 1));
    spanableInfo.setSpan(new Clickable(spanableInfo.toString()), 0, end + 1 - start, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    append(spanableInfo);
    //setMovementMethod()该方法必须调用,否则点击事件不响应
    setMovementMethod(LinkMovementMethod.getInstance());
    text = text.substring(end + 1);
    LogUtils.e(spanableInfo.toString());
  }
}

代码示例来源:origin: robolectric/robolectric

@Test
public void testToString() {
 assertThat(spanStr.toString()).isSameAs(TEST_STRING);
}

代码示例来源:origin: stackoverflow.com

private static void applySpan(SpannableString spannable, String target, ClickableSpan span) {
 final String spannableString = spannable.toString();
 final int start = spannableString.indexOf(target);
 final int end = start + target.length();
 spannable.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}

代码示例来源:origin: stackoverflow.com

SpannableString spannableString = new SpannableString("@");
 Drawable d = getResources().getDrawable(R.drawable.your_drawable);
 d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
 ImageSpan span = new ImageSpan(d, ImageSpan.ALIGN_BOTTOM);
 spannableString.setSpan(span, spannableString.toString().indexOf("@"),  spannableString.toString().indexOf("@")+1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
 yourTextView.setText(spannableString);

代码示例来源:origin: stackoverflow.com

TextView tv = (TextView) findViewById(R.id.textView1);

SpannableString spannableString = new 
            SpannableString(getResources().getString(R.string.foo));

ForegroundColorSpan fcs = new 
            ForegroundColorSpan(getResources().getColor(R.color.bluish));

spannableString.setSpan(fcs, spannableString.toString().indexOf(" ") + 1,
            spannableString.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);

tv.setText(spannableString);

代码示例来源:origin: jamorham/xDrip-plus

public static String nanoStatus(final String module) {
  final SpannableString result = nanoStatusColor(module);
  return result != null ? result.toString() : null;
}

代码示例来源:origin: stackoverflow.com

SpannableString formatted = new SpannableString(urlString);
Pattern url = Pattern.compile("(https?)://[-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|]");
Matcher matcher = url.matcher(urlString.toLowerCase());

//Here you save the string in upper case
SpannableString stringUpperCase = new SpannableString(formatted.toString().toUpperCase());

while (matcher.find()) {

  int begIndex = matcher.start();
  int endIdx = begIndex + matcher.group().length() - 1;
  stringUpperCase.setSpan(new ForegroundColorSpan(R.color.Red),
            0, formatted.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
      }
TextView text = (TextView) findViewById(R.id.textView);
text.setText(string);

代码示例来源:origin: NightscoutFoundation/xDrip

public static String nanoStatus(final String module) {
  final SpannableString result = nanoStatusColor(module);
  return result != null ? result.toString() : null;
}

代码示例来源:origin: jamorham/xDrip-plus

public static String nanoStatus(final String module) {
  final SpannableString result = nanoStatusColor(module);
  return result != null ? result.toString() : null;
}

代码示例来源:origin: baidu/speech-samples

@Override
public void handleMessage(Message msg) {
  super.handleMessage(msg);
  int what = msg.what;
  switch (what) {
    case PRINT:
      print(msg);
      break;
    case UI_CHANGE_INPUT_TEXT_SELECTION:
      if (msg.arg1 <= mInput.getText().length()) {
        mInput.setSelection(0,msg.arg1);
      }
      break;
    case UI_CHANGE_SYNTHES_TEXT_SELECTION:
      SpannableString colorfulText = new SpannableString(mInput.getText().toString());
      if (msg.arg1 <= colorfulText.toString().length()) {
        colorfulText.setSpan(new ForegroundColorSpan(Color.GRAY), 0, msg.arg1, Spannable
            .SPAN_EXCLUSIVE_EXCLUSIVE);
        mInput.setText(colorfulText);
      }
      break;
    default:
      break;
  }
}

代码示例来源:origin: easefun/polyv-android-sdk-2.0-demo

@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
  String all = et_talk.getText().toString();
  String msg = all.substring(all.indexOf(" : ") + 3);
  if (all.length() < length || all.indexOf(" : ") == -1)
    msg = "";
  if (start < length && !et_talk.getText().toString().equals(spanStr.toString() + msg)) {
    final SpannableString spanStr1 = new SpannableString(spanStr + msg);
    spanStr1.setSpan(new BackgroundColorSpan(Color.MAGENTA), 0, spanStr1.length() - msg.length() - 3,
        Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanStr1.setSpan(
        new ForegroundColorSpan(getResources().getColor(R.color.center_left_text_color_gray)), 0,
        spanStr1.length() - msg.length() - 3, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    et_talk.setText(spanStr1);
    et_talk.setSelection(et_talk.getText().toString().length());
  }
}

代码示例来源:origin: ymback/NGA-CLIENT-VER-OPEN-SOURCE

private PostParam getPostParam() {
  Intent intent = getIntent();
  String tid = intent.getStringExtra(ParamKey.KEY_TID);
  int fid = intent.getIntExtra(ParamKey.KEY_FID, -7);
  String title = intent.getStringExtra("title");
  String pid = intent.getStringExtra(ParamKey.KEY_PID);
  String action = intent.getStringExtra(ParamKey.KEY_ACTION);
  String prefix = intent.getStringExtra("prefix");
  if (prefix != null && prefix.startsWith("[quote][pid=") && prefix.endsWith("[/quote]\n")) {
    SpannableString spanString = new SpannableString(prefix);
    spanString.setSpan(new BackgroundColorSpan(-1513240), 0, prefix.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spanString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), prefix.indexOf("[b]Post by"), prefix.indexOf("):[/b]") + 5, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    prefix = spanString.toString();
  }
  PostParam act = new PostParam(tid, "", "");
  act.setPostAction(action);
  act.setPostFid(fid);
  act.setPostPid(pid);
  act.setPostContent(prefix);
  act.setPostSubject(title);
  return act;
}

代码示例来源:origin: jamorham/xDrip-plus

private void updateWatch() {
  final SpannableString result = nanoStatusColor(parameter);
  color_watch.set(result != null ? result : empty);
  watch.set(result != null ? result.toString() : "");
}

代码示例来源:origin: NightscoutFoundation/xDrip

private void updateWatch() {
  final SpannableString result = nanoStatusColor(parameter);
  color_watch.set(result != null ? result : empty);
  watch.set(result != null ? result.toString() : "");
}

代码示例来源:origin: jamorham/xDrip-plus

private void updateWatch() {
  final SpannableString result = nanoStatusColor(parameter);
  color_watch.set(result != null ? result : empty);
  watch.set(result != null ? result.toString() : "");
}

代码示例来源:origin: guanpj/JReadHub

@Override
public void bindData(RelevantTopicBean relevantTopicBean, int position) {
  mRelevantTopicBean = relevantTopicBean;
  LocalDate date = relevantTopicBean.getCreatedAt().toLocalDate();
  int year = date.getYear();
  int month = date.getMonthValue();
  int day = date.getDayOfMonth();
  if (year == OffsetDateTime.now().getYear()) {
    mTxtDate.setText(mContext.getString(R.string.month__day, month, day));
  } else {
    SpannableString spannableTitle = SpannableString.valueOf(mContext.getString(R.string.month__day__year, month, day, year));
    spannableTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_topic_detail_news_author)),
        spannableTitle.toString().indexOf("\n") + 1,
        spannableTitle.toString().indexOf("\n") + 5,
        Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    mTxtDate.setText(spannableTitle);
  }
  mTxtContent.setText(relevantTopicBean.getTitle());
  mDividerTop.setVisibility(getItemViewType() == VIEW_TYPE_TOP || getItemViewType() == VIEW_TYPE_ONLY_ONE ? View.INVISIBLE : View.VISIBLE);
  mDividerBottom.setVisibility(getItemViewType() == VIEW_TYPE_BOTTOM || getItemViewType() == VIEW_TYPE_ONLY_ONE ? View.INVISIBLE : View.VISIBLE);
}

代码示例来源:origin: ValleZ/Paper-Wallet

int keyTypeStart = keyTypeLabel.toString().indexOf(keyType.toString());
keyTypeLabel.setSpan(new StyleSpan(Typeface.BOLD), keyTypeStart, keyTypeStart + keyType.length(),
    SpannableStringBuilder.SPAN_INCLUSIVE_INCLUSIVE);
        !keyPair.privateKey.isPublicKeyCompressed)) {
  String compressionStrToSpan = keyType.toString().substring(keyType.toString().indexOf(',') + 2);
  int start = keyTypeLabel.toString().indexOf(compressionStrToSpan);
  if (start >= 0) {
    ClickableSpan switchPublicKeyCompressionSpan = new ClickableSpan() {

代码示例来源:origin: guanpj/JReadHub

@Override
  protected void convert(BaseViewHolder holder, RelevantTopicBean relevantTopicBean) {
    LocalDate date = relevantTopicBean.getCreatedAt().toLocalDate();
    int year = date.getYear();
    int month = date.getMonthValue();
    int day = date.getDayOfMonth();
    if (year == OffsetDateTime.now().getYear()) {
      holder.setText(R.id.txt_date, mContext.getString(R.string.month__day, month, day));
    } else {
      SpannableString spannableTitle = SpannableString.valueOf(mContext.getString(R.string.month__day__year, month, day, year));
      spannableTitle.setSpan(new ForegroundColorSpan(ContextCompat.getColor(mContext, R.color.text_topic_detail_news_author)),
          spannableTitle.toString().indexOf("\n") + 1,
          spannableTitle.toString().indexOf("\n") + 5,
          Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
      holder.setText(R.id.txt_date, spannableTitle);
    }
    holder.setText(R.id.txt_topic_trace_content, relevantTopicBean.getTitle());
    holder.setVisible(R.id.view_top_line, holder.getItemViewType() == VIEW_TYPE_TOP || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true);
    holder.setVisible(R.id.view_bottom_line, holder.getItemViewType() == VIEW_TYPE_BOTTOM || holder.getItemViewType() == VIEW_TYPE_ONLY_ONE ? false : true);
  }
}

代码示例来源:origin: stackoverflow.com

@Override
  public boolean onMenuItemSelected(int featureId, MenuItem item) {
  if (item.getTitle() instanceof SpannableString) {
    SpannableString sp = (SpannableString)item.getTitle();
    Object[] spans = sp.getSpans(0, sp.length(), Object.class);
    if (spans != null && spans.length > 0) {
      // set text without span markups, need for super.onMenuItemSelected(featureId, item);
      item.setTitleCondensed(sp.toString());
      boolean result = super.onMenuItemSelected(featureId, item);
      item.setTitleCondensed(sp);
      return result;
    }
  }

  return super.onMenuItemSelected(featureId, item);
}

代码示例来源:origin: derry/delion

int start = title.toString().indexOf(mOrigin);
TextUtils.copySpansFrom(origin, 0, origin.length(), Object.class, title, start);

相关文章