欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2022-08-06 20:59:15
看下代码调用链: public final void setText(CharSequence text) { setText(text, mBufferType); } 最终调到重载方法: private void setText(CharSequence text, BufferType type, boolean notifyBefore, int oldlen) { ....... ....

看下代码调用链:

 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

相关标签: android