import { createMuiTheme } from '@material-ui/core/styles';
const theme = createMuiTheme({
typography: {
fontFamily: 'Roboto, sans-serif', // default Material-UI font
body1: {
fontFamily: 'Open Sans, sans-serif', // your chosen Google Font
},`enter code here`
// You can also set the font family for other typography variants, like body2, h1, h2, etc.
},
});
import { ThemeProvider } from '@material-ui/core/styles';
// Wrap your app or specific components with the ThemeProvider
const App = () => {
return (
<ThemeProvider theme={theme}>
{/* Your app or components */}
</ThemeProvider>
);
};
2条答案
按热度按时间jbose2ul1#
有人在另一个主题中这样做了
cbjzeqam2#
首先,选择您要使用的Google字体并将其导入到项目中。您可以通过在HTML文件的部分中添加指向Google Fonts CSS文件的链接来实现这一点,或者通过使用google-fonts-loader之类的包在代码中动态导入字体。
导入字体后,可以使用Material-UI提供的createMuiTheme()函数创建新的MuiTheme对象。
在MuiTheme对象中,可以指定用于项目中各种排版组件的字体系列。例如,要设置正文文本的字体系列,可以将body 1属性设置为具有fontFamily属性的对象,该属性指定所导入字体的名称。下面是一个例子:
创建MuiTheme对象后,您可以使用它来 Package 您的应用程序或使用Material-UI提供的ThemeProvider组件的特定组件。下面是一个例子: