如何在React Native中设置视图后面的整体背景颜色

How to set the overall background color behind the view in React-Native

本文关键字:颜色 背景 视图 React Native 设置      更新时间:2023-09-26

有没有办法设置在React Native中渲染的视图背后的整体背景颜色?例如,如果我用marginTop: 30设置视图的样式,那么视图上方会有一个空白。我想知道是否有办法改变这种背景颜色?

renderStoriesListView() {
if (this.state.dataSource.getRowCount() === 0) {
  return (
    <Loading>top stories</Loading>
  )
} else {
  return (
    <View style={{marginTop: 30, backgroundColor: 'black'}}>
    <RefreshableListView
      dataSource={this.state.dataSource}
      renderRow={this.renderStory}
      loadData={this.loadTopStories}
      refreshDescription="Refreshing top stories"
      refreshingIndictatorComponent={<Refreshing />}  
    /></View>
  )
}
},
  render() {
return this.renderStoriesListView()
}
})

试试这个。。。

<View style={{backgroundColor: 'black'}}>
<View style={{marginTop: 30}}>
<RefreshableListView
  dataSource={this.state.dataSource}
  renderRow={this.renderStory}
  loadData={this.loadTopStories}
  refreshDescription="Refreshing top stories"
  refreshingIndictatorComponent={<Refreshing />}  
/></View></View>