How do certain apps record everything we type in android?
It installs an Accessibility Service. These services are usually used as screen readers (like TalkBack), and thus have access to on-screen text. It is thus able to record on-screen information. If you install the app, you'll notice it prompts you to register it as an accessibility service so as to collect input information.

However, one limitation of this is it's unable to collect data within password fields.