3

如何在 React Native Paper 中将主题设置为深色主题?在我所有的屏幕中,所有的<View>'s 仍然有白色背景。

const theme = {
      ...DarkTheme,
      colors: {
        ...DarkTheme.colors,
        primary: '#2d3436',
        accent: '#1C1C1C',
        background : '#636e72'
      }
    };

render() {
   return(
      <PaperProvider theme={theme}>
         <App />
      </PaperProvider>
  );
}
4

1 回答 1

2

应用主题和提供者级别不会更改所有视图。导出时您必须使用“withTheme”,这将提供可用于访问颜色的主题道具。

import { withTheme } from 'react-native-paper';
const Test = ({ theme,children }) => {
  const { colors } = theme;
  return (
    <View style={{ backgroundColor: colors.background }}>
     {children}
    </View>
  );
};

export default withTheme(Test);

如果您想为所有视图使用相同的主题,请创建一个自定义包装器组件,该组件设置颜色,如上

于 2020-08-12T03:53:15.927 回答