Change frametitle color on overlay

Is there a way to change the base colors of the frame (for example its title) depending on the overlay?

I have read Beamer: locally change frametitle? and Beamer change frametitle font size just for one slide, but I need something even more local, to take into account overlays.

Apparently, the frametitle color needs to be set before the frame starts, and overlays don't exist at this point.

MWE:

\documentclass{beamer}

\begin{document}

\begin{frame}
% Ignored, so no point in setting overlays here
\setbeamercolor{frametitle}{fg=black,bg=green}

% Ideally I would be able to use
% \only<2>{\setbeamercolor{frametitle}{fg=black,bg=green}}

\frametitle{%
\only<1>{Random...}%
\only<2>{Important!}
}

\only<1>{This frame should have the default theme}

\only<2>{This frame should have a green title background}

\end{frame}

\end{document}


You can use the usual way of changing color, font, etc. in the course of the document, and redraw the frame using \againframe.

\documentclass{beamer}

\begin{document}

\begin{frame}<1>[label=test]
\frametitle{%
\only<1>{Random...}%
\only<2>{Important!}
}

\only<1>{This frame should have the default theme}

\only<2>{This frame should have a green title background}

\end{frame}

{
\setbeamercolor{frametitle}{fg=black,bg=green}

\againframe<2>{test}
}

\end{document}