Transistor toggle by NPN and PNP - how is it build?
Expanding on Tony Stewart's answer which should work for 3.3 V logic, the circuit below will work on 5 V logic as well.



Figure 1. One GPIO pin can drive two LEDs. Source: 1 GPIO, multiple LEDs.

How it works


When the output is switched low, current will flow from the positive supply via R1 and the L1, green, to the output pin. L1 will illuminate. L2, red, will be shorted out and will be dark.
When the output is switched high, current will flow from the pin through R2 and L2. The red LED will illuminate and the green will be dark.
If the output is tri-stated (wired as an input or disconnected by program control) a current will flow through R1, L1, R2, L2 and both LEDs will glow dimly. On a 3.3 V device the voltage wouldn’t be high enough to illuminate both LEDs significantly so they would appear dark.