Cressi-sub makes two beanies for diving, one lycra and the other polyester. Pinnacle makes a very light beany type cap, with a velcro chin strap. The Cressi beanies have to be secured by the mask strap. Tucking them under the mask itself may cause a leak. They are best used for long periods of snorkeling, or stored in a pocket and pulled on when you surface after scuba. Leisurepro sells all three, as do other large operations. Henderson makes a nice microprene hood that is super thin and stretchy. There are also lycra full hoods available.
Cloth Bandannas are not made for water use, and don't really do the job. A swimmer's cap made of light material, or the Henderson are probably best for what you want. I carry a polyester Cressi beany in my bc, and use it if i'm going to be floating around for a while in the hot tropic sun after a dive. They fit easily, are well made, are effective for the purpose you intend. About $10.