当前位置: 移动技术网 > 移动技术>移动开发>Android > Android 中 setText(“android“) 怎样调用invalidate()重新绘制界面?

Android 中 setText(“android“) 怎样调用invalidate()重新绘制界面?

2020年07月27日  | 移动技术网移动技术  | 我要评论

看下代码调用链:

 public final void setText(CharSequence text) {
        setText(text, mBufferType);
 }

  最终调到重载方法:

 private void setText(CharSequence text, BufferType type,
                         boolean notifyBefore, int oldlen) {

        .......
   
   //这里处理文字发生变化
    if (needEditableForNotification) {
            sendAfterTextChanged((Editable) text);
    } else {
            // Always notify AutoFillManager - it will return right away if autofill is 
            disabled.
            notifyAutoFillManagerAfterTextChangedIfNeeded();
    }

}
 void sendAfterTextChanged(Editable text) {
        if (mListeners != null) {
            final ArrayList<TextWatcher> list = mListeners;
            final int count = list.size();
            for (int i = 0; i < count; i++) {
                list.get(i).afterTextChanged(text);
            }
        }

        // Always notify AutoFillManager - it will return right away if autofill is 
        disabled.
        notifyAutoFillManagerAfterTextChangedIfNeeded();

        hideErrorIfUnchanged();
    }
private void notifyAutoFillManagerAfterTextChangedIfNeeded() {
        // It is important to not check whether the view is important for autofill
        // since the user can trigger autofill manually on not important views.
        if (!isAutofillable()) {
            return;
        }
        final AutofillManager afm = mContext.getSystemService(AutofillManager.class);
        if (afm != null) {
            if (DEBUG_AUTOFILL) {
                Log.v(LOG_TAG, "sendAfterTextChanged(): notify AFM for text=" + mText);
            }
            afm.notifyValueChanged(TextView.this);
        }
    }

 接下来跳进 AutofillManager

 public void notifyValueChanged(View view) {
  .....
  
     if (mLastAutofilledData == null) {
        view.setAutofilled(false);
     } else {
        .....
     }
 }

  最终调用View的 invalidate(),重新绘制UI

 public void setAutofilled(boolean isAutofilled) {
        boolean wasChanged = isAutofilled != isAutofilled();

        if (wasChanged) {
            if (isAutofilled) {
                mPrivateFlags3 |= PFLAG3_IS_AUTOFILLED;
            } else {
                mPrivateFlags3 &= ~PFLAG3_IS_AUTOFILLED;
            }

            invalidate();
        }
    }

 

本文地址:https://blog.csdn.net/czh0616101038/article/details/107556478

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网