I do this in my demo programs:
...
BEFORE INPUT
LET frm = DIALOG.getForm()
AFTER FIELD login
IF g_sl.login IS NULL OR g_sl.login = " " THEN
CALL frm.setFieldStyle("login","invalid")
ELSE
CALL frm.setFieldStyle("login","valid")
END IF
...
The styles are simply:
<Style name=".valid">
<StyleAttribute name="backgroundColor" value="#D0F5D0"/>
</Style>
<Style name=".invalid">
<StyleAttribute name="backgroundColor" value="#F5D0D0"/>
</Style>