简体   繁体   English

material-ui:AppBar 未使用主题中定义的颜色

[英]material-ui : AppBar not using color defined in the theme

I've created a theme using this site:我使用这个网站创建了一个主题:

https://cimdalli.github.io/mui-theme-generator/ https://cimdalli.github.io/mui-theme-generator/

I need the primary color to be RED and the secondary BLUE.我需要主要颜色是红色和次要蓝色。 But I need the AppBar to be some of grey.但我需要 AppBar 是灰色的。 In the preview the AppBar is using the color I need:在预览中,AppBar 正在使用我需要的颜色:

在此处输入图像描述

The code generated looks like this:生成的代码如下所示:

const theme = createMuiTheme({
  palette: {
    primary: { main: '#f44336' },
    secondary: { main: '#7b1fa2' }
  },
  appBar: {
    color:  '#bdbdbd' ,
  }
});

function App() {
  return (
    <MuiThemeProvider theme={theme}>
      <div className="App">
        <AppBar position="fixed">
          <Toolbar />
        </AppBar>
      </div>
    </MuiThemeProvider>
  );
}

But the AppBar is always taking de primary color.但 AppBar 始终采用 de 原色。 If I set it to default now it's white.如果我现在将其设置为默认值,则它是白色的。 Never the grey grey I need.从来没有我需要的灰色。

I've made this codeSandbox to test this theme:我制作了这个 codeSandbox 来测试这个主题:

https://codesandbox.io/s/material-ui-themes-4inc1?file=/src/index.js https://codesandbox.io/s/material-ui-themes-4inc1?file=/src/index.js

Any help would be appreciated!任何帮助,将不胜感激! Thanks谢谢

Well after some test it seems that if you put the style directly to the AppBar element it works: https://codesandbox.io/s/material-ui-themes-izlou好吧,经过一些测试,如果您将样式直接放在 AppBar 元素上,它似乎可以工作: https://codesandbox.io/s/material-ui-themes-izlou

it also seems that if you change the primary: { main: '#f44336' } hexa value, it does change the background color of your appBar似乎如果您更改primary: { main: '#f44336' } hexa 值,它确实会更改您的 appBar 的背景颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM