0

正在创建一个应用程序,其中 edittext 将样式范围添加到文本的某些位置

editable.setSpan(new StyleSpan(Typeface.BOLD), start, start+replacement.length(),Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

我的问题是,如果用户添加,将删除跨越文本样式之前的一些文本或空白,如何避免这种情况?

    int SPAN_COMPOSING = 256;
    int SPAN_EXCLUSIVE_EXCLUSIVE = 33;
    int SPAN_EXCLUSIVE_INCLUSIVE = 34;
    int SPAN_INCLUSIVE_EXCLUSIVE = 17;
    int SPAN_INCLUSIVE_INCLUSIVE = 18;
    int SPAN_INTERMEDIATE = 512;
    int SPAN_MARK_MARK = 17;
    int SPAN_MARK_POINT = 18;
    int SPAN_PARAGRAPH = 51;
    int SPAN_POINT_MARK = 33;
    int SPAN_POINT_MARK_MASK = 51;
    int SPAN_POINT_POINT = 34;
    int SPAN_PRIORITY = 16711680;
    int SPAN_PRIORITY_SHIFT = 16;
    int SPAN_USER = -16777216;
    int SPAN_USER_SHIFT = 24;

在我的情况下我需要使用哪种类型?

4

1 回答 1

-1

您可以使用如下代码。

editable.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                // here is your code to change position
            }

            @Override
            public void afterTextChanged(Editable s) {

            }

        });
于 2017-08-21T07:22:26.397 回答