It's a very complex question.
First thing to say is that the Elizabethans didn't have "straight" and "gay", but that it was widely accepted socially (though, of course, not religiously) that a man could be attracted to men (usually boys) and women in a fluid way. It wasn't about being gay, straight, bi or anything else. It was just who you wanted to sleep with and be in love with right then.
The sextet of Sonnet 20, which addresses a male, offers a pretty clear indication that its speaker is thinking sexually about a male ("thing" means "penis", and "nothing" means vagina):
And for a woman wert thou first created;
Till Nature, as she wrought thee, fell a-doting,
And by addition me of thee defeated,
By adding one thing to my purpose nothing.
But since she prick'd thee out for women's pleasure,
Mine be thy love and thy love's use their treasure.
Shakespeare's plays also contain several characters who can be (and are!) interpreted as "gay": notably the Antonios in "The Merchant of Venice" and "Twelfth Night". Shakespeare's friend, Christopher Marlowe, certainly slept with other men - and Shakespeare's comedies are packed full of sexual/gender confusion.
So Shakespeare wouldn't think of himself as "gay", but may well have had relationships with a man (what happened to his marriage to Anne H. all those years he was in London?). As usual with Shakespeare's biography, we can never really know.