An amphiphilic spiropyran-based random copolymer containing methacrylic acid unit has been prepared and investigated with obvious negative solvatochromism in five different solvents. It was found that the polarity of comonomer influenced the photochromic behavior of spiropyran. The synthesized copolymer exhibited a good reversible behavior in aqueous solution: the addition of strong acid promoted the isomerization from spiropyran (SP) to merocyanine (MC), and the inverse process was achieved by the introduction of strong base. Much more importance, the effect of comonomer was utilized for the selective Co2þ recognition. The locations of the maximum absorption peak stay almost as same as MC when it is complexed with Cu2þ, Mn2þ and Hg2þ. The location, however, moves from 551 nm to 526 nm upon complexation with Co2þ. The obvious color change of the solution from purple to claret-red after complexation with Co2þ was observed. This interesting phenomenon is practically convenient for the visual recognition of Co2þ