React-native 阴影未出现

标签 react-native shadow

我正在尝试在我的 View 下方添加阴影,从我在网上找到的内容来看,这应该非常简单:

shadowOffset: { width: 10, height: 10 },
shadowColor: 'black',
shadowOpacity: 1.0,

但问题是阴影根本没有出现。

这是我的组件

<View style={styles.shadow}>
    <View style={styles.box} >
        <View style={styles.ListComponent}>
            <Text style={styles.itemText}>Livestream</Text>
        </View>
    </View>
</View>

在我的样式表中:

const styles = StyleSheet.create({
    shadow: {
    shadowOffset: { width: 10, height: 10 },
    shadowColor: 'black',
    shadowOpacity: 1.0
},

这有什么原因或者我错过了什么吗?

最佳答案

影子在 IO 上工作吗? Android 和 IOS 在 React-Native 中工作 ≠。对于 Android,它适用于 elevation .

const styles = StyleSheet.create({
shadow: {
  shadowOffset: { width: 10, height: 10 },
  shadowColor: 'black',
  shadowOpacity: 1,
  elevation: 3,
  // background color must be set
  backgroundColor : "#0000" // invisible color
}

否则,请尝试为阴影组件设置背景颜色:)

关于React-native 阴影未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44908580/

相关文章:

html - 将 box-shadow 添加到非矩形 div(使用 border-radius)

android - react-native-keyboard-aware-scroll-view 中平台之间的不同行为

reactjs - React-Native 抽屉式菜单在堆栈导航器屏幕内打开

javascript - 在场景中响应 native 禁用抽屉

javascript - 更新状态不更新 View

css - 如何为 Font Awesome svg 图标添加阴影?

javascript - React-Native Button onPress 不工作

shadow - 如何实现这种css3阴影效果?

HTML+CSS 阴影、垂直菜单、文本位置

css - 奇怪的阴影框随机出现 - CSS 错误?