So I know how to set up an ip address on the Raspberry Pi to static and how to change it back to dynamic, but is there a way to incorporate both?

For example, will I be able to plug my Raspberry Pi on a known network and use the static ip address, but use the dhcp protocol instead if it is not on a known network?

With the instructions to the article I linked, will I have to manually switch back the static ip address and the dynamic ip address? That would be a problem since I mostly work with a headless Raspberry Pi.

Also, can I set static ip addresses for multiple gateways?