I am trying to use my custom color for AppBar
header. The AppBar
has title 'My AppBar'. I am using white as my primary theme color. It works well for the bar but the 'title' of the AppBar
is also using same 'white' color'
Here is my code:
import React from 'react'; import * as Colors from 'material-ui/styles/colors'; import MuiThemeProvider from 'material-ui/styles/MuiThemeProvider'; import getMuiTheme from 'material-ui/styles/getMuiTheme'; import AppBar from 'material-ui/AppBar'; import TextField from 'material-ui/TextField'; const muiTheme = getMuiTheme({ palette: { textColor: Colors.darkBlack, primary1Color: Colors.white, primary2Color: Colors.indigo700, accent1Color: Colors.redA200, pickerHeaderColor: Colors.darkBlack, }, appBar: { height: 60, }, }); class Main extends React.Component { render() { // MuiThemeProvider takes the theme as a property and passed it down the hierarchy // using React's context feature. return ( <MuiThemeProvider muiTheme={muiTheme}> <AppBar title="My AppBar"> <div> < TextField hintText = "username" / > < TextField hintText = "password" / > </div> </AppBar> </MuiThemeProvider> ); } } export default Main;
But, the palette styles override the AppBar
'title' color and no title is displaying. Should I include something or I have misplaced any ?
And this is my output :
To set the background color of the Material UI drawer, we call the makeStyles function to create the styles. Then we can apply the styles with the useStyles hook returned by makeStyles . We call makeStyles with an object that has the properties set to objects with the styles.
Step 1: Locate the MaterialApp widget. Step 2: Inside the MaterialApp, add the theme parameter with ThemeData class assigned. Step 3: Inside the ThemeData add the appBarTheme parameter and then assign the AppBarTheme class. Step 4: Inside the AppBarTheme , specify the color parameter and set the color.
If you ant to change your Appbar background in material ui design ....try following code
<AppBar style={{ background: '#2E3B55' }}>
or if you want to apply className then follow this step
first of all make create const var
const style = { background : '#2E3B55'; }; <AppBar className={style}>
From what I see in the material-ui sources, appBar title color is set by palette.alternateTextColor. If you add it to your style definition like that:
const muiTheme = getMuiTheme({ palette: { textColor: Colors.darkBlack, primary1Color: Colors.white, primary2Color: Colors.indigo700, accent1Color: Colors.redA200, pickerHeaderColor: Colors.darkBlack, alternateTextColor: Colors.redA200 }, appBar: { height: 60, }, });
You should see your title without need to style it manually inside each component.
There are more styling parameters to MuiTheme described here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With