Use a transistor as a spdt relay

I want to turn ON a green led if an ir phototransistor is sending current, if not i want a red led to turn it ON and the green on OFF. I think is possible to do this with an spdt 5v relay, but is it possible to do this with a transistor?

Yes you should be able to use the IR device to directly switch on one led, and a transistor to then invert the signal and switch off/on the other alternately.

if not i want a red led to turn it OFF and the green on OFF

doesn't make sense to me! The answer above is probably right, but you might want to be
more clear about the two states you want when the IR diode is illuminated and when
it isn't.

Sorry, i just edit my post, basically I only want one green led to be on and the red one off, then if there is no current turn on the red one and turn off the green one

MarkT:
doesn't make sense to me! The answer above is probably right, but you might want to be
more clear about the two states you want when the IR diode is illuminated and when
it isn't.

Try this:
When transistor is on, current flows thru Red LED, Green LED anode is pulled low.
When transistor is off, Red cathode is at level of Green anode, if high enough (say 3.2V) then Red LED only has 1.8V across it, not enough voltage to turn it in.

with resistor values

I tried that and with a HIGH on the input the red is on and the green off but with a LOW on the input both leds are on because the red led current is in series with the green led.

I got it to work as requested by following the suggestion given of adding another transistor inverter driven by the same input signal that drives the red led but with a 1 k pullup on the collector so when it is off, the base resistor that drives the transistor that drives the green led is driven through the 1 k pullup.