android - 我需要像这个按钮这样的 Box shadow 属性来反应原生
问题描述
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
解决方案
React-Native Button 组件没有 style 属性。如果要自定义按钮样式,则必须使用TouchableOpacity
或创建自定义按钮TouchableNativeFeedback
。
import * as React from 'react';
import { Text, View, StyleSheet, TouchableOpacity } from 'react-native';
export default function App() {
return (
<View style={styles.container}>
<TouchableOpacity style={styles.buttonStyle}>
<Text style={styles.textStyle}>OK</Text>
</TouchableOpacity>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
buttonStyle: {
width: '80%',
padding: 10,
backgroundColor: '#E13C17',
borderRadius: 10,
shadowColor: '#000',
shadowOffset: {
width: 0,
height: 2,
},
shadowOpacity: 0.25,
shadowRadius: 3.84,
elevation: 5,
},
textStyle: {
textAlign: 'center',
color: '#FFF',
fontSize: 18,
},
});
希望这对您有所帮助。随意怀疑。
推荐阅读
- matlab - 如何在两个 for 循环中显示很多时间的结果?
- hadoop - 用两次双引号括起来并用逗号分隔到 HIVE 表中的数据?
- javascript - 从表格工作中过滤数据,但再次搜索后没有发现任何内容[Angular,Pagination,Table]
- git - 想要从 git 的一个分支中删除所有提交
- scala - Gatling:test 目标似乎编译了两次
- angular - Rxjs:它是如何完成的和 async/await
- c++ - Qt 应用程序的布局设计问题
- sql - 在sql server中将表达式转换为数据类型日期时间错误的算术溢出错误
- sql-server - SQL Server XML 数据 - 不返回值
- objective-c - 什么是崩溃响应 NSfileHandle.fd_monitoring?