Material UI v4 AppBar 不会更改主题

2024-01-03

我有 Appbar(在 MUI v4 中)

<AppBar position="fixed" className={classes.appBar}>
  <Toolbar style={{ padding: 0 }}>
    <... />
  </Toolbar>
</AppBar>

在我的页面上,当我将 MUI 主题更改为 Light 时,它的默认颜色没有改变

import { MuiThemeProvider, createMuiTheme } from "@material-ui/core/styles";

const theme = createMuiTheme({
  palette: {
    type: "dark"
  }
});

ReactDOM.render(
  <MuiThemeProvider theme={theme}>
    <Index />
  </MuiThemeProvider>,
  document.getElementById("root")
);

如果我将其添加到调色板中,那么我会得到黑色背景...我想当我将类型从浅色更改为深色时可以更改整体调色板..?

primary: {
  main: "#000000"
}

注意:此答案适用于 MUI v4

On https://material-ui.com/ https://material-ui.com/如果您将主题从浅色更改为深色(使用 AppBar 中的灯泡图标),您会发现 AppBar 没有变化。

AppBar默认使用原色作为背景色,从亮到暗切换时原色不会改变。

如果您有一个 AppBarcolor="default",那么当从亮到暗切换时它会发生变化。您可以在 Simple App Bar 演示中看到这一点:https://material-ui.com/demos/app-bar/#simple-app-bar https://material-ui.com/demos/app-bar/#simple-app-bar

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Material UI v4 AppBar 不会更改主题 的相关文章

随机推荐