Android 中 setText(“android“) 怎样调用invalidate()重新绘制界面?
程序员文章站
2022-04-10 15:03:39
看下代码调用链: 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
上一篇: 唐武宗死后,皇位为何由叔叔李忱继承?
下一篇: 清朝都打到家门口了,南明两位藩王还在内战