[source code]TextView source code

When it comes to TextView, I think that it should be very simple to use. However, as the base class of all controls that display text, it is still very complicated to fully explore the capabilities of TextView. I recently made a requirement to recognize the pasted Tao password in the input box with limited length. Because my understanding of TextView is too superficial and there are countless bugs, I specially looked at the source code to learn it (I heard from iOS students that the external interfaces of each platform are relatively close, It's also a good way to recognize the writing system).
Mainly focus on the set interface exposed by TextView and hooks.
- TransformationMethod
provides an interface for transforming text. The callback timing is between beforeTextChanged and onTextChanged. That is to say, the modified content given by the two callbacks may be inconsistent. At the same time, this is a set method, not an add method, so it will overwrite each other. setAllCaps, is implemented with this interface.
- Callback for TextWatcher
changes, callback when setText. At the same time, it will be passed to the Editable as a span, and the Editable will also call back when it changes. Magical setup
- MovementMethod
initialization callback timing is between beforeTextChanged and onTextChanged. The timing of calling the corresponding callback is confusing, and there is no unified short-circuit logic.
- OnEditorActionListener, EditorAction callback
- InputFilter, currently only the longest input character control is in use, and the callback is before beforeTextChanged. When inflate, if maxLength is not set, it will be empty
- KeyListener, the specification of the allowed input content.
- Directly engaged, various flags.
- setAutoLinkMask, handles the link between beforeTextChanged and onTextChanged
- setCompoundDrawables, when drawing on onDraw, it will call requestLayout
- setCustomSelectionActionModeCallback, custom menu instance
- setEllipsize, processed in TextUtils, BoringLayout uses
- set various maximum and minimum, onMeasure uses
- setImeActionLabel to customize keyboard behavior

By the way, remember the role of Spanned#SPAN_xxCLUSIVE_xxCLUSIVE:
the input occurs before the span. If it is Inclusive, the newly input content has its own span. If it is Exclusive, it will not take span.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325837046&siteId=291194637