Define 2 charStyles with proper fillCollor settings. Assign keyboard shortcuts to them.
(i.e. Num 0/Shift-Num 0)
use those shortcuts as a switcher.
I'm new to java so i'm not sure how to set up the script. How would I set this up?
You do not need script to define styles. If your goal is to switch between two colors with some text selected - do it using application interface.