本文整理了Java中android.text.Selection.getSelectionEnd()
方法的一些代码示例,展示了Selection.getSelectionEnd()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Selection.getSelectionEnd()
方法的具体详情如下:
包路径:android.text.Selection
类名称:Selection
方法名:getSelectionEnd
暂无
代码示例来源:origin: seven332/EhViewer
int b = Selection.getSelectionEnd(buffer);
代码示例来源:origin: baiyuliang/QRobot
/**
* 向输入框里添加表情
* */
public static void insert(EditText input,CharSequence text) {
int iCursorStart = Selection.getSelectionStart((input.getText()));
int iCursorEnd = Selection.getSelectionEnd((input.getText()));
if (iCursorStart != iCursorEnd) {
((Editable) input.getText()).replace(iCursorStart, iCursorEnd, "");
}
int iCursor = Selection.getSelectionEnd((input.getText()));
((Editable) input.getText()).insert(iCursor, text);
}
代码示例来源:origin: CooLoongWu/CoolChat
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
Editable editable = edit_name.getText();
int maxLength = 20;
int length = editable.length();//原字符串长度
if (length > maxLength) {//如果原字符串长度大于最大长度
int selectEndIndex = Selection.getSelectionEnd(editable);//getSelectionEnd:获取光标结束的索引值
String str = editable.toString();//旧字符串
String newStr = str.substring(0, maxLength);//截取新字符串
edit_name.setText(newStr);
editable = edit_name.getText();
int newLength = editable.length();//新字符串长度
if (selectEndIndex > newLength) {//如果光标结束的索引值超过新字符串长度
selectEndIndex = editable.length();
ToastUtils.showShort(NameActivity.this, "最多只能输入" + maxLength + "个字哦");
}
Selection.setSelection(editable, selectEndIndex);//设置新光标所在的位置
} else {
text_num.setText(s.length() + "/20");
}
}
代码示例来源:origin: baiyuliang/QRobot
/**
* 删除图标执行事件
* 注:如果删除的是表情,在删除时实际删除的是tempText即图片占位的字符串,所以必需一次性删除掉tempText,才能将图片删除
* */
public static void delete(EditText input) {
if (input.getText().length() != 0) {
int iCursorEnd = Selection.getSelectionEnd(input.getText());
int iCursorStart = Selection.getSelectionStart(input.getText());
if (iCursorEnd > 0) {
if (iCursorEnd == iCursorStart) {
if (isDeletePng(input,iCursorEnd)) {
String st = "[p/_000.png]";
((Editable) input.getText()).delete(
iCursorEnd - st.length(), iCursorEnd);
} else {
((Editable) input.getText()).delete(iCursorEnd - 1,
iCursorEnd);
}
} else {
((Editable) input.getText()).delete(iCursorStart,
iCursorEnd);
}
}
}
}
代码示例来源:origin: geniusgithub/AndroidDialer
public void hideSoftKey() {
if (DBG) {
Log.d(LOG_TAG, "--- hidesoftkey");
}
if (!mEST.isFocused()) {
return;
}
mSkr.mNewStart = Selection.getSelectionStart(mEST.getText());
mSkr.mNewEnd = Selection.getSelectionEnd(mEST.getText());
InputMethodManager imm =
(InputMethodManager) mEST.getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mEST.getWindowToken(), 0, mSkr);
}
代码示例来源:origin: geniusgithub/AndroidDialer
public void showSoftKey(int oldSelStart, int oldSelEnd) {
if (DBG) {
Log.d(LOG_TAG, "--- showsoftkey");
}
if (!mEST.isFocused() || isSoftKeyBlocked()) {
return;
}
mSkr.mNewStart = Selection.getSelectionStart(mEST.getText());
mSkr.mNewEnd = Selection.getSelectionEnd(mEST.getText());
InputMethodManager imm =
(InputMethodManager) getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
if (imm.showSoftInput(mEST, 0, mSkr) && mSkr != null) {
Selection.setSelection(getText(), oldSelStart, oldSelEnd);
}
}
代码示例来源:origin: sunhapper/SpEditTool
@Override
public boolean onKeyEvent(KeyEvent keyEvent, Spannable text) {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_DEL && keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
int selectionStart = Selection.getSelectionStart(text);
int selectionEnd = Selection.getSelectionEnd(text);
MarkSpan[] markSpans = text.getSpans(selectionStart, selectionEnd, MarkSpan.class);
if (markSpans != null && markSpans.length > 0) {
MarkSpan span = markSpans[0];
int spanStart = text.getSpanStart(span);
int spanEnd = text.getSpanEnd(span);
if (spanEnd == selectionStart) {
Selection.setSelection(text, spanStart, spanEnd);
if (needSelectionFlag()) {
return selectionEnd == selectionStart;
}
}
}
}
return false;
}
代码示例来源:origin: sunhapper/SpEditTool
@Override
public void onSpanChanged(Spannable text, Object what, int ostart, int oend, int nstart, int nend) {
if (what == Selection.SELECTION_END && oend != nstart) {
IntegratedSpan[] spans = text.getSpans(nstart, nend, IntegratedSpan.class);
if (spans != null && spans.length > 0) {
IntegratedSpan integratedSpan = spans[0];
int spanStart = text.getSpanStart(integratedSpan);
int spanEnd = text.getSpanEnd(integratedSpan);
int index = (Math.abs(nstart - spanEnd) > Math.abs(nstart - spanStart)) ? spanStart : spanEnd;
Selection.setSelection(text, Selection.getSelectionStart(text), index);
}
}
if (what == Selection.SELECTION_START && oend != nstart) {
IntegratedSpan[] spans = text.getSpans(nstart, nend, IntegratedSpan.class);
if (spans != null && spans.length > 0) {
IntegratedSpan integratedSpan = spans[0];
int spanStart = text.getSpanStart(integratedSpan);
int spanEnd = text.getSpanEnd(integratedSpan);
int index = (Math.abs(nstart - spanEnd) > Math.abs(nstart - spanStart)) ? spanStart : spanEnd;
Selection.setSelection(text, index, Selection.getSelectionEnd(text));
}
}
if (what instanceof BreakableSpan && ((BreakableSpan) what).isBreak()) {
text.removeSpan(what);
}
}
}
代码示例来源:origin: PaXLiCh/FormattEditText
value.setSpan(selection, Selection.getSelectionStart(value), Selection.getSelectionEnd(value), Spanned.SPAN_MARK_MARK);
代码示例来源:origin: derry/delion
int selectionEnd = Selection.getSelectionEnd(currentText);
int autocompleteIndex = currentText.getSpanStart(mAutocompleteSpan);
代码示例来源:origin: geniusgithub/AndroidDialer
int oldSelEnd = Selection.getSelectionEnd(getText());
superResult = super.onTouchEvent(event);
if (isFocused()) {
if (editting) {
mManager.showSoftKey(Selection.getSelectionStart(getText()),
Selection.getSelectionEnd(getText()));
} else {
mManager.showSoftKey(oldSelStart, oldSelEnd);
代码示例来源:origin: andforce/iBeebo
int b = Selection.getSelectionEnd(buffer);
代码示例来源:origin: zhe525069676/WeiBoLayout
int b = Selection.getSelectionEnd(buffer);
内容来源于网络,如有侵权,请联系作者删除!