android.widget.EditText#getEditableText ( )源码实例Demo

下面列出了android.widget.EditText#getEditableText ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: MyBookshelf   文件: SourceEditActivity.java
@Override
public void sendText(@NotNull String txt) {
    if (isEmpty(txt)) return;
    View view = getWindow().getDecorView().findFocus();
    if (view instanceof EditText) {
        EditText editText = (EditText) view;
        int start = editText.getSelectionStart();
        int end = editText.getSelectionEnd();
        Editable edit = editText.getEditableText();//获取EditText的文字
        if (start < 0 || start >= edit.length()) {
            edit.append(txt);
        } else {
            edit.replace(start, end, txt);//光标所在位置插入文字
        }
    }
}
 
源代码2 项目: a   文件: SourceEditActivity.java
private void insertTextToEditText(String txt) {
    if (isEmpty(txt)) return;
    View view = getWindow().getDecorView().findFocus();
    if (view instanceof EditText) {
        EditText editText = (EditText) view;
        int start = editText.getSelectionStart();
        int end = editText.getSelectionEnd();
        Editable edit = editText.getEditableText();//获取EditText的文字
        if (start < 0 || start >= edit.length()) {
            edit.append(txt);
        } else {
            edit.replace(start, end, txt);//光标所在位置插入文字
        }
    }
}
 
源代码3 项目: lttrs-android   文件: ChipDrawableSpan.java
public static void reset(EditText editText) {
    final Editable editable = editText.getEditableText();
    if (TextUtils.isEmpty(editable)) {
        return;
    }
    editable.clearSpans();
    ChipDrawableSpan.apply(editText.getContext(), editable, editText.hasFocus());
}
 
源代码4 项目: HaoReader   文件: SourceEditActivity.java
private void insertTextToEditText(String txt) {
    if (TextUtils.isEmpty(txt)) return;
    View view = getWindow().getDecorView().findFocus();
    if (view instanceof EditText) {
        EditText editText = (EditText) view;
        int start = editText.getSelectionStart();
        int end = editText.getSelectionEnd();
        Editable edit = editText.getEditableText();//获取EditText的文字
        if (start < 0 || start >= edit.length()) {
            edit.append(txt);
        } else {
            edit.replace(start, end, txt);//光标所在位置插入文字
        }
    }
}
 
源代码5 项目: YCCustomText   文件: SpanTextHelper.java
/**
 * 修改加粗样式
 */
public void bold(EditText lastFocusEdit) {
    //获取editable对象
    Editable editable = lastFocusEdit.getEditableText();
    //获取当前选中的起始位置
    int start = lastFocusEdit.getSelectionStart();
    //获取当前选中的末尾位置
    int end = lastFocusEdit.getSelectionEnd();
    HyperLogUtils.i("bold select  Start:" + start + "   end:  " + end);
    if (checkNormalStyle(start, end)) {
        return;
    }
    new BoldStyle().applyStyle(editable, start, end);
}
 
源代码6 项目: YCCustomText   文件: SpanTextHelper.java
/**
 * 修改斜体样式
 */
public void italic(EditText lastFocusEdit) {
    Editable editable = lastFocusEdit.getEditableText();
    int start = lastFocusEdit.getSelectionStart();
    int end = lastFocusEdit.getSelectionEnd();
    HyperLogUtils.i("italic select  Start:" + start + "   end:  " + end);
    if (checkNormalStyle(start, end)) {
        return;
    }
    new ItalicStyle().applyStyle(editable, start, end);
}
 
源代码7 项目: YCCustomText   文件: SpanTextHelper.java
/**
 * 修改加粗斜体样式
 */
public void boldItalic(EditText lastFocusEdit) {
    Editable editable = lastFocusEdit.getEditableText();
    int start = lastFocusEdit.getSelectionStart();
    int end = lastFocusEdit.getSelectionEnd();
    HyperLogUtils.i("boldItalic select  Start:" + start + "   end:  " + end);
    if (checkNormalStyle(start, end)) {
        return;
    }
    new BoldItalicStyle().applyStyle(editable, start, end);
}
 
源代码8 项目: YCCustomText   文件: SpanTextHelper.java
/**
 * 修改删除线样式
 */
public void strikeThrough(EditText lastFocusEdit) {
    Editable editable = lastFocusEdit.getEditableText();
    int start = lastFocusEdit.getSelectionStart();
    int end = lastFocusEdit.getSelectionEnd();
    HyperLogUtils.i("strikeThrough select  Start:" + start + "   end:  " + end);
    if (checkNormalStyle(start, end)) {
        return;
    }
    new StrikeThroughStyle().applyStyle(editable, start, end);
}
 
源代码9 项目: YCCustomText   文件: SpanTextHelper.java
/**
 * 修改下划线样式
 */
public void underline(EditText lastFocusEdit) {
    Editable editable = lastFocusEdit.getEditableText();
    int start = lastFocusEdit.getSelectionStart();
    int end = lastFocusEdit.getSelectionEnd();
    HyperLogUtils.i("underline select  Start:" + start + "   end:  " + end);
    if (checkNormalStyle(start, end)) {
        return;
    }
    new UnderlineStyle().applyStyle(editable, start, end);
}
 
源代码10 项目: Simpler   文件: InputMethodUtils.java
/**
 * 设置输入框的光标到末尾
 */
public static void setEditTextSelectionToEnd(EditText editText) {
    Editable editable = editText.getEditableText();
    Selection.setSelection((Spannable) editable, editable.toString().length());
}
 
源代码11 项目: Android-Architecture   文件: KeyboardUtil.java
/**
 * 设置输入框的光标到末尾
 */
public static void setEditTextSelectionToEnd(EditText editText) {
    Editable editable = editText.getEditableText();
    Selection.setSelection((Spannable) editable,
            editable.toString().length());
}
 
源代码12 项目: Overchan-Android   文件: PostFormMarkup.java
public static void markup(int markType, EditText commentField, int feature) {
    Editable comment = commentField.getEditableText();
    String text = comment.toString();
    int selectionStart = Math.max(0, commentField.getSelectionStart());
    int selectionEnd = Math.min(text.length(), commentField.getSelectionEnd());
    text = text.substring(selectionStart, selectionEnd);
    
    if (markType == BoardModel.MARK_WAKABAMARK) {
        switch (feature) {
            case FEATURE_BOLD:
                comment.replace(selectionStart, selectionEnd, "**" + text.replace("\n", "**\n**") + "**");
                commentField.setSelection(selectionStart + 2);
                break;
            case FEATURE_ITALIC:
                comment.replace(selectionStart, selectionEnd, "*" + text.replace("\n", "*\n*") + "*");
                commentField.setSelection(selectionStart + 1);
                break;
            case FEATURE_STRIKE:
                StringBuilder strike = new StringBuilder();
                for (String s : text.split("\n")) {
                    strike.append(s);
                    for (int i=0; i<s.length(); ++i) strike.append("^H");
                    strike.append('\n');
                }
                comment.replace(selectionStart, selectionEnd, strike.substring(0, strike.length() - 1));
                commentField.setSelection(selectionStart);
                break;
            case FEATURE_SPOILER:
                comment.replace(selectionStart, selectionEnd, "%%" + text.replace("\n", "%%\n%%") + "%%");
                commentField.setSelection(selectionStart + 2);
                break;
            case FEATURE_QUOTE:
                comment.replace(selectionStart, selectionEnd, ">" + text.replace("\n", "\n>"));
                break;
        }
    } else if (markType == BoardModel.MARK_BBCODE) {
        switch (feature) {
            case FEATURE_BOLD:
                comment.replace(selectionStart, selectionEnd, "[b]" + text + "[/b]");
                commentField.setSelection(selectionStart + 3);
                break;
            case FEATURE_ITALIC:
                comment.replace(selectionStart, selectionEnd, "[i]" + text + "[/i]");
                commentField.setSelection(selectionStart + 3);
                break;
            case FEATURE_UNDERLINE:
                comment.replace(selectionStart, selectionEnd, "[u]" + text + "[/u]");
                commentField.setSelection(selectionStart + 3);
                break;
            case FEATURE_STRIKE:
                comment.replace(selectionStart, selectionEnd, "[s]" + text + "[/s]");
                commentField.setSelection(selectionStart + 3);
                break;
            case FEATURE_SPOILER:
                comment.replace(selectionStart, selectionEnd, "[spoiler]" + text + "[/spoiler]");
                commentField.setSelection(selectionStart + 9);
                break;
            case FEATURE_QUOTE:
                comment.replace(selectionStart, selectionEnd, ">" + text.replace("\n", "\n>"));
                break;
        }
    } else if (markType == BoardModel.MARK_4CHAN) {
        switch (feature) {
            case FEATURE_BOLD:
                comment.replace(selectionStart, selectionEnd, "**" + text.replace("\n", "**\n**") + "**");
                commentField.setSelection(selectionStart + 2);
                break;
            case FEATURE_ITALIC:
                comment.replace(selectionStart, selectionEnd, "*" + text.replace("\n", "*\n*") + "*");
                commentField.setSelection(selectionStart + 1);
                break;
            case FEATURE_UNDERLINE:
                comment.replace(selectionStart, selectionEnd, "__" + text.replace("\n", "__\n__") + "__");
                commentField.setSelection(selectionStart + 2);
                break;
            case FEATURE_SPOILER:
                comment.replace(selectionStart, selectionEnd, "[spoiler]" + text + "[/spoiler]");
                commentField.setSelection(selectionStart + 9);
                break;
            case FEATURE_QUOTE:
                comment.replace(selectionStart, selectionEnd, ">" + text.replace("\n", "\n>"));
                break;
        }
    }
}