android.text.Selection.setSelection()方法的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(7.0k)|赞(0)|评价(0)|浏览(323)

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

Selection.setSelection介绍

暂无

代码示例

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

@Implementation
protected void setDefaultKeyMode(int keyMode) {
 mDefaultKeyMode = keyMode;
 // Some modes use a SpannableStringBuilder to track & dispatch input events
 // This list must remain in sync with the switch in onKeyDown()
 switch (mDefaultKeyMode) {
  case Activity.DEFAULT_KEYS_DISABLE:
  case Activity.DEFAULT_KEYS_SHORTCUT:
   mDefaultKeySsb = null;      // not used in these modes
   break;
  case Activity.DEFAULT_KEYS_DIALER:
  case Activity.DEFAULT_KEYS_SEARCH_LOCAL:
  case Activity.DEFAULT_KEYS_SEARCH_GLOBAL:
   mDefaultKeySsb = new SpannableStringBuilder();
   Selection.setSelection(mDefaultKeySsb, 0);
   break;
  default:
   throw new IllegalArgumentException();
 }
}

代码示例来源:origin: rey5137/material

@Override
public void onClick(View v) {
  int position = (Integer)v.getTag();
  if(position == 0)
    removeSpan(mSelectedSpan);
  else
    replaceSpan(mSelectedSpan, (Recipient)mReplacementAdapter.getItem(position));
  Selection.setSelection(getText(), getText().length());
  dismissReplacementPopup();
}

代码示例来源:origin: termux/termux-app

if (initialText != null) {
  input.setText(initialText);
  Selection.setSelection(input.getText(), initialText.length());

代码示例来源:origin: nickbutcher/plaid

@Override
public boolean onTouchEvent(TextView textView, Spannable spannable, MotionEvent event) {
  boolean handled = false;
  if (event.getAction() == MotionEvent.ACTION_DOWN) {
    pressedSpan = getPressedSpan(textView, spannable, event);
    if (pressedSpan != null) {
      pressedSpan.setPressed(true);
      Selection.setSelection(spannable, spannable.getSpanStart(pressedSpan),
          spannable.getSpanEnd(pressedSpan));
      handled = true;
    }
  } else if (event.getAction() == MotionEvent.ACTION_MOVE) {
    TouchableUrlSpan touchedSpan = getPressedSpan(textView, spannable, event);
    if (pressedSpan != null && touchedSpan != pressedSpan) {
      pressedSpan.setPressed(false);
      pressedSpan = null;
      Selection.removeSelection(spannable);
    }
  } else {
    if (pressedSpan != null) {
      pressedSpan.setPressed(false);
      super.onTouchEvent(textView, spannable, event);
      handled = true;
    }
    pressedSpan = null;
    Selection.removeSelection(spannable);
  }
  return handled;
}

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

@Test
public void append_whenSelectionReachesToEnd_shouldExtendSelectionToTheEnd() throws Exception {
 textView.setText("12", TextView.BufferType.EDITABLE);
 Selection.setSelection(textView.getEditableText(), 0, 2);
 textView.append("3");
 assertEquals(3, textView.getSelectionEnd());
 assertEquals(0, textView.getSelectionStart());
}

代码示例来源:origin: seven332/EhViewer

Selection.setSelection(buffer,
    buffer.getSpanStart(link[0]),
    buffer.getSpanEnd(link[0]));

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

@Test
public void append_whenSelectionIsAtTheEnd_shouldKeepSelectionAtTheEnd() throws Exception {
 textView.setText("1", TextView.BufferType.EDITABLE);
 Selection.setSelection(textView.getEditableText(), 0, 0);
 textView.append("2");
 assertEquals(0, textView.getSelectionEnd());
 assertEquals(0, textView.getSelectionStart());
 Selection.setSelection(textView.getEditableText(), 2, 2);
 textView.append("3");
 assertEquals(3, textView.getSelectionEnd());
 assertEquals(3, textView.getSelectionStart());
}

代码示例来源:origin: PrivacyApps/html-textview

link[0].onClick(widget);
} else if (action == MotionEvent.ACTION_DOWN) {
  Selection.setSelection(buffer,
      buffer.getSpanStart(link[0]),
      buffer.getSpanEnd(link[0]));

代码示例来源:origin: jaydenxiao2016/AndroidFire

Selection.setSelection(buffer,
    buffer.getSpanStart(mClickLinks[0]),
    buffer.getSpanEnd(mClickLinks[0]));

代码示例来源:origin: Naoki2015/CircleDemo

Selection.setSelection(buffer,
    buffer.getSpanStart(mClickLinks[0]),
    buffer.getSpanEnd(mClickLinks[0]));

代码示例来源:origin: seven332/EhViewer

Selection.setSelection(buffer, bestend, beststart);
return true;
Selection.setSelection(buffer, beststart, bestend);
return true;

代码示例来源:origin: armcha/AutoLinkTextView

@Override
public boolean onTouchEvent(TextView textView, final Spannable spannable, MotionEvent event) {
  int action  = event.getAction();
  if (action == MotionEvent.ACTION_DOWN) {
    pressedSpan = getPressedSpan(textView, spannable, event);
    if (pressedSpan != null) {
      pressedSpan.setPressed(true);
      Selection.setSelection(spannable, spannable.getSpanStart(pressedSpan),
          spannable.getSpanEnd(pressedSpan));
    }
  } else if (action == MotionEvent.ACTION_MOVE) {
    TouchableSpan touchedSpan = getPressedSpan(textView, spannable, event);
    if (pressedSpan != null && touchedSpan != pressedSpan) {
      pressedSpan.setPressed(false);
      pressedSpan = null;
      Selection.removeSelection(spannable);
    }
  } else {
    if (pressedSpan != null) {
      pressedSpan.setPressed(false);
      super.onTouchEvent(textView, spannable, event);
    }
    pressedSpan = null;
    Selection.removeSelection(spannable);
  }
  return true;
}

代码示例来源:origin: huangfangyi/YiChat

private void editTextEnd() {
  CharSequence charSequence = et_password.getText();
  if (charSequence instanceof Spannable) {
    Spannable spanText = (Spannable) charSequence;
    Selection.setSelection(spanText, charSequence.length());
  }
}

代码示例来源:origin: XiqingLiu/SuJin

/**
 * 设置输入框的光标到末尾
 */
public static final void setEditTextSelectionToEnd(EditText editText) {
  Editable editable = editText.getEditableText();
  Selection.setSelection((Spannable) editable,
      editable.toString().length());
}

代码示例来源:origin: linkedin/Spyglass

@Override
  public Editable newEditable(@NonNull CharSequence source) {
    MentionsEditable text = new MentionsEditable(source);
    Selection.setSelection(text, 0);
    return text;
  }
}

代码示例来源:origin: fookwood/Launcher3

private void clearTypedText() {
  mDefaultKeySsb.clear();
  mDefaultKeySsb.clearSpans();
  Selection.setSelection(mDefaultKeySsb, 0);
}

代码示例来源:origin: concretesolutions/canarinho

private void atualizaTexto(Editable editable, String valor) {
  mudancaInterna = true;
  final InputFilter[] oldFilters = editable.getFilters();
  editable.setFilters(new InputFilter[] {});
  editable.replace(0, editable.length(), valor);
  editable.setFilters(oldFilters);
  if (valor.equals(editable.toString())) {
    // TODO: estudar implantar a manutenção da posição do cursor
    Selection.setSelection(editable, valor.length());
  }
  mudancaInterna = false;
}

代码示例来源:origin: klinker24/launcher3

@Override
public void clearSearchResult() {
  if (mApps.setOrderedFilter(null)) {
    mAppsRecyclerView.onSearchResultsChanged();
  }
  // Clear the search query
  mSearchQueryBuilder.clear();
  mSearchQueryBuilder.clearSpans();
  Selection.setSelection(mSearchQueryBuilder, 0);
}

代码示例来源:origin: fookwood/Launcher3

@Override
  public void clearSearchResult() {
    mApps.setOrderedFilter(null);
    mAppsRecyclerView.onSearchResultsChanged();

    // Clear the search query
    mSearchQueryBuilder.clear();
    mSearchQueryBuilder.clearSpans();
    Selection.setSelection(mSearchQueryBuilder, 0);
  }
}

代码示例来源:origin: MichaelRocks/CallMeMaybe

@Override
public SpannableStringBuilder replace(final int start, final int end, final CharSequence text,
  final int textStart, final int textEnd) {
 phoneFormatter.format(this, start, end, text, textStart, textEnd);
 final CharSequence phoneNumber = phoneFormatter.getFormattedPhone();
 final SpannableStringBuilder result = super.replace(0, length(), phoneNumber, 0, phoneNumber.length());
 final int selection = phoneFormatter.getSelection();
 if (selection != -1 && selection <= result.length()) {
  Selection.setSelection(result, selection);
 }
 return result;
}

相关文章