The earliest-recorded specific use of �gay' to mean �homosexual', depending on which source you believe, appeared (a) in a Gertrude Stein piece - Miss Furr & Miss Skeene - published in 1922 or (b) in a dictionary of prison/underworld slang published in 1935 in the USA. Whichever it is, it was clearly an Americanism.
However, as far back as the 16th century, it meant "living a dissipated lifestyle" or uninhibited by the demands of normal morality. A man might then, for example, have been described as �a gay dog'...suggesting he had an inordinate interest in women.
In the 19th century, if a man or a woman was described as �gay', it meant he/she was a prostitute. They were so called because they dressed in bright clothing. In the USA, a �gay cat' - as opposed to a gay dog! - was a young tramp who attached himself to an older one for protection and, in return, provided sexual services. The �cat' element was perhaps an abbreviation of �catamite'. It is relatively easy, therefore, to see how it came to take on the homosexual meaning of today.
The word was not adopted by homosexuals themselves until the 1960s. The idea that it came from an acronym, GAY = Good As You, is an urban legend.