本文整理汇总了Java中android.widget.EditText.getSelectionEnd方法的典型用法代码示例。如果您正苦于以下问题:Java EditText.getSelectionEnd方法的具体用法?Java EditText.getSelectionEnd怎么用?Java EditText.getSelectionEnd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.EditText
的用法示例。
在下文中一共展示了EditText.getSelectionEnd方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: insertAtCursor
import android.widget.EditText; //导入方法依赖的package包/类
public static void insertAtCursor(@NonNull EditText editText, @NonNull String text) {
String oriContent = editText.getText().toString();
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
Logger.e(start, end);
if (start >= 0 && end > 0 && start != end) {
editText.setText(editText.getText().replace(start, end, text));
} else {
int index = editText.getSelectionStart() >= 0 ? editText.getSelectionStart() : 0;
Logger.e(start, end, index);
StringBuilder builder = new StringBuilder(oriContent);
builder.insert(index, text);
editText.setText(builder.toString());
editText.setSelection(index + text.length());
}
}
示例2: input
import android.widget.EditText; //导入方法依赖的package包/类
public static void input(EditText editText, String emoji) {
if (editText == null || TextUtils.isEmpty(emoji)) {
return;
}
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
if (start < 0) {
editText.append(emoji);
} else {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){
int length = getEditTextMaxLength(editText);
if(length>0 && start+emoji.length() > length){
return;
}
}
editText.getText().replace(Math.min(start, end), Math.max(start, end), emoji, 0, emoji.length());
if(editText.getText().length() < start+emoji.length()){
editText.getText().delete(Math.min(start, end), editText.getText().length());
}
}
}
示例3: getSelectionRange
import android.widget.EditText; //导入方法依赖的package包/类
@JSMethod
public void getSelectionRange(String callbackId) {
EditText hostView;
Map<String, Object> result = new HashMap<>(2);
if ((hostView = getHostView()) != null) {
int start = hostView.getSelectionStart();
int end = hostView.getSelectionEnd();
if (!hostView.hasFocus()) {
//The default behavior, same as iOS and web
start = 0;
end = 0;
}
result.put(Constants.Name.SELECTION_START, start);
result.put(Constants.Name.SELECTION_END, end);
}
WXBridgeManager.getInstance().callback(getInstanceId(), callbackId, result, false);
}
示例4: input2OSC
import android.widget.EditText; //导入方法依赖的package包/类
public static void input2OSC(EditText editText, Emojicon emojicon) {
if (editText == null || emojicon == null) {
return;
}
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
if (start < 0) {
// 没有多选时,直接在当前光标处添加
editText.append(emojicon.getRemote());
} else {
// 将已选中的部分替换为表情(当长按文字时会多选刷中很多文字)
String str = emojicon.getRemote();
editText.getText().replace(Math.min(start, end),
Math.max(start, end), str, 0, str.length());
}
}
示例5: addCode
import android.widget.EditText; //导入方法依赖的package包/类
public static void addCode(@NonNull EditText editText) {
try {
String source = editText.getText().toString();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
String substring = source.substring(selectionStart, selectionEnd);
String result;
if (hasNewLine(source, selectionStart))
result = "```\n" + substring + "\n```\n";
else
result = "\n```\n" + substring + "\n```\n";
editText.getText().replace(selectionStart, selectionEnd, result);
editText.setSelection(result.length() + selectionStart - 5);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: addQuote
import android.widget.EditText; //导入方法依赖的package包/类
public static void addQuote(@NonNull EditText editText) {
String source = editText.getText().toString();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
String substring = source.substring(selectionStart, selectionEnd);
String result;
if (hasNewLine(source, selectionStart)) {
result = "> " + substring;
} else {
result = "\n> " + substring;
}
editText.getText().replace(selectionStart, selectionEnd, result);
editText.setSelection(result.length() + selectionStart);
}
示例7: input2OSC
import android.widget.EditText; //导入方法依赖的package包/类
/**
* 输入Emoji表情到 EditText
*
* @param editText EditText
* @param emojicon Emojicon
*/
public static void input2OSC(EditText editText, Emojicon emojicon) {
if (editText == null || emojicon == null) {
return;
}
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
if (start < 0) {
// 没有多选时,直接在当前光标处添加
editText.append(displayEmoji(editText.getResources(),
emojicon.getRemote(), (int) editText.getTextSize()));
} else {
// 将已选中的部分替换为表情(当长按文字时会多选刷中很多文字)
Spannable str = displayEmoji(editText.getResources(),
emojicon.getRemote(), (int) editText.getTextSize());
editText.getText().replace(Math.min(start, end),
Math.max(start, end), str, 0, str.length());
}
}
示例8: insert2Input
import android.widget.EditText; //导入方法依赖的package包/类
void insert2Input(String strToInsert) {
EditText txtInput = (EditText)findViewById(R.id.edtSmartMathInput);
int nSelectionStart = txtInput.getSelectionStart();
int nSelectionEnd = txtInput.getSelectionEnd();
if (nSelectionStart < 0 || nSelectionEnd < 0
|| nSelectionStart > txtInput.getText().length()
|| nSelectionEnd > txtInput.getText().length()
|| nSelectionStart > nSelectionEnd) { // invalid selection
txtInput.setText(strToInsert);
txtInput.setSelection(txtInput.getText().length());
} else { // valid selection, insert the text
txtInput.getText().replace(nSelectionStart, nSelectionEnd, strToInsert);
txtInput.setSelection(nSelectionStart + strToInsert.length());
}
}
示例9: replaceBodySelectionTextTo
import android.widget.EditText; //导入方法依赖的package包/类
@Override
public void replaceBodySelectionTextTo(String replyText) {
if (nonNull(mInputController)) {
EditText edit = mInputController.getInputField();
int selectionStart = edit.getSelectionStart();
int selectionEnd = edit.getSelectionEnd();
edit.getText().replace(selectionStart, selectionEnd, replyText);
}
}
示例10: input
import android.widget.EditText; //导入方法依赖的package包/类
public static void input(EditText editText, Emojicon emojicon) {
if (editText == null || emojicon == null) {
return;
}
int start = editText.getSelectionStart();
int end = editText.getSelectionEnd();
if (start < 0) {
editText.append(emojicon.getEmoji());
} else {
editText.getText().replace(Math.min(start, end), Math.max(start, end), emojicon.getEmoji(), 0, emojicon.getEmoji().length());
}
}
示例11: findChar
import android.widget.EditText; //导入方法依赖的package包/类
private int findChar(EditText editor, String s) {
int selectionEnd = editor.getSelectionEnd();
while (selectionEnd > -1 && editor.getText().charAt(selectionEnd) != s.charAt(0)) {
selectionEnd--;
}
return selectionEnd;
}
示例12: addList
import android.widget.EditText; //导入方法依赖的package包/类
public static void addList(@NonNull EditText editText, @NonNull String list) {
String tag = list + " ";
String source = editText.getText().toString();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
String substring = source.substring(0, selectionStart);
int line = substring.lastIndexOf(10);
if (line != -1) {
selectionStart = line + 1;
} else {
selectionStart = 0;
}
substring = source.substring(selectionStart, selectionEnd);
String[] split = substring.split("\n");
StringBuilder stringBuffer = new StringBuilder();
if (split.length > 0)
for (String s : split) {
if (s.length() == 0 && stringBuffer.length() != 0) {
stringBuffer.append("\n");
continue;
}
if (!s.trim().startsWith(tag)) {
if (stringBuffer.length() > 0) stringBuffer.append("\n");
stringBuffer.append(tag).append(s);
} else {
if (stringBuffer.length() > 0) stringBuffer.append("\n");
stringBuffer.append(s);
}
}
if (stringBuffer.length() == 0) {
stringBuffer.append(tag);
}
editText.getText().replace(selectionStart, selectionEnd, stringBuffer.toString());
editText.setSelection(stringBuffer.length() + selectionStart);
}
示例13: addHeader
import android.widget.EditText; //导入方法依赖的package包/类
public static void addHeader(@NonNull EditText editText, int level) {
String source = editText.getText().toString();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
StringBuilder result = new StringBuilder();
String substring = source.substring(selectionStart, selectionEnd);
if (!hasNewLine(source, selectionStart))
result.append("\n");
IntStream.range(0, level).forEach(integer -> result.append("#"));
result.append(" ").append(substring);
editText.getText().replace(selectionStart, selectionEnd, result.toString());
editText.setSelection(selectionStart + result.length());
}
示例14: addItalic
import android.widget.EditText; //导入方法依赖的package包/类
public static void addItalic(@NonNull EditText editText) {
String source = editText.getText().toString();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
String substring = source.substring(selectionStart, selectionEnd);
String result = "_" + substring + "_ ";
editText.getText().replace(selectionStart, selectionEnd, result);
editText.setSelection(result.length() + selectionStart - 2);
}
示例15: addBold
import android.widget.EditText; //导入方法依赖的package包/类
public static void addBold(@NonNull EditText editText) {
String source = editText.getText().toString();
int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd();
String substring = source.substring(selectionStart, selectionEnd);
String result = "**" + substring + "** ";
editText.getText().replace(selectionStart, selectionEnd, result);
editText.setSelection(result.length() + selectionStart - 3);
}