Skip to main content

主题

例子#

基本用法#

export function App() {    const [isDark, setIsDark] = useState(false);    const switchTheme = () =>        setIsDark((prevTheme: boolean) => {            const isDarkTheme = !prevTheme;            const context = getAppContext();            const themeImage = context.getThemeImage();            if (isDarkTheme) {                const themeDark = new ThemePredefined_Dark();                themeDark.SetStyle(themeImage, 0); // switch to dark theme            } else {                themeImage.ResetTheme(); // reset to light theme            }            return isDarkTheme;        });
    return (        <Window>            <DemoLayout>                <Button text="Toggling Themes" onClick={switchTheme}></Button>            </DemoLayout>        </Window>    );}

这个例子演示了如何切换主题,各组件的明/暗主题是内置的,只需要整体切换即可:

toggle theme

API#

export interface IThemePredefined_Dark {    SetStyle(theme: IThemeImage, nStyle: number): void;}
export interface IThemeImage {    ResetTheme(): void;}