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

看下代码调用链:

 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();
        }
    }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值