在 React Native 中,当 DrawerNavigator 与 StackNavigator 一起使用时,它无法更改 Header 的背景颜色
In React Native When DrawerNavigator using with StackNavigator it cannot change the Background color of Header
export default DrawerNavigator({
MainScreen: {
screen: MainScreen,
},
CreateItem:{
screen: CreateItem,
},
MyitemScreen: {
screen: MyitemScreen,
},
Settings: {
screen: Settings,
},
Buying: {
screen: Buying,
},
Messages: {
screen: Messages,
},
Notifications: {
screen: Notifications,
}, Profile: {
screen: Profile,
}, Logout: {
screen: Logout,
},
},
{
drawerPosition:'left',
initialRouteName:'MainScreen',
drawerBackgroundColor:'white',
drawerWidth:250,
});
然后
export default class MainScreen extends Component {
static navigationOptions =
{
title:'Home',
headerMode:"float",
headerStyle: {
backgroundColor: 'green',
elevation: null
},
headerTitleStyle: {
fontWeight: '300',
color: '#ffffff',
fontSize: 20,
flex:1,
textAlign:"center"
},
};
主屏幕的背景 header 已更改为绿色,但 header
中仍然出现白色
我假设你使用的是 'React-Navigation'
为你的静态导航选项试试这个道具
static navigationsOptions = ({navigation}) = {
return{
title : 'My title',
headerStyle = {background : 'green'
}
}
顺便说一句,我可能误解了你的问题。贴个图可能更清楚。
export default DrawerNavigator({
MainScreen: {
screen: MainScreen,
},
CreateItem:{
screen: CreateItem,
},
MyitemScreen: {
screen: MyitemScreen,
},
Settings: {
screen: Settings,
},
Buying: {
screen: Buying,
},
Messages: {
screen: Messages,
},
Notifications: {
screen: Notifications,
}, Profile: {
screen: Profile,
}, Logout: {
screen: Logout,
},
},
{
drawerPosition:'left',
initialRouteName:'MainScreen',
drawerBackgroundColor:'white',
drawerWidth:250,
});
然后
export default class MainScreen extends Component {
static navigationOptions =
{
title:'Home',
headerMode:"float",
headerStyle: {
backgroundColor: 'green',
elevation: null
},
headerTitleStyle: {
fontWeight: '300',
color: '#ffffff',
fontSize: 20,
flex:1,
textAlign:"center"
},
};
主屏幕的背景 header 已更改为绿色,但 header
中仍然出现白色我假设你使用的是 'React-Navigation'
为你的静态导航选项试试这个道具
static navigationsOptions = ({navigation}) = {
return{
title : 'My title',
headerStyle = {background : 'green'
}
}
顺便说一句,我可能误解了你的问题。贴个图可能更清楚。