【发布时间】:2021-03-15 08:17:16
【问题描述】:
我正在使用原生按钮并尝试通过按下按钮来下载图像。它在 IOS 中运行良好,但在 Android 中无法运行。这是我的代码
<View
style={{
marginVertical: hp("2%"),
marginHorizontal: wp("15%"),
textAlign: "center",
width: "100%",
}}
>
<Button
onPress={() => downloadFile()}
style={{
backgroundColor: "#fff",
width: "60%",
borderRadius: 0,
}}
block
>
<Text
style={{
color: "black",
fontSize: RFPercentage(2.1),
fontFamily: "BalsamiqSansBold",
}}
>
ADD TO PHOTOS
</Text>
</Button>
</View>
在 IOS 中按下按钮时会调用 downloadFile() 函数,但在 Android 中它不起作用。
我也尝试过这样的控制台登录新闻
<Button
onPress={() => console.log("Button Clicked")}
style={{
backgroundColor: "#fff",
width: "60%",
borderRadius: 0,
}}
block
>
它在 IOS 中有效,但在 Android 中无效。
此外,如果我在 Android 中像这样直接调用 onPress 上的函数,它会自动记录 Button Clicked 而不被按下。我试图找出所有可能的方法来解决它,但我没有得到这个问题的确切原因。
<Button
onPress={console.log("Button Clicked")}
style={{
backgroundColor: "#fff",
width: "60%",
borderRadius: 0,
}}
block
>
【问题讨论】:
标签: react-native button react-native-android react-native-ios onpress