Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native 本机基本按钮的Onpress()在Android上不起作用_React Native_Button_React Native Android_React Native Ios_Onpress - Fatal编程技术网

React native 本机基本按钮的Onpress()在Android上不起作用

React native 本机基本按钮的Onpress()在Android上不起作用,react-native,button,react-native-android,react-native-ios,onpress,React Native,Button,React Native Android,React Native Ios,Onpress,我正在使用本机的基本按钮,并试图通过按下按钮下载图像。它在IOS上运行得非常好,但在Android上却不起作用。这是我的密码 <View style={{ marginVertical: hp("2%"), marginHorizontal: wp("15%"), textAlign: "center",

我正在使用本机的基本按钮,并试图通过按下按钮下载图像。它在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>


下载文件()}
风格={{
背景颜色:“fff”,
宽度:“60%”,
边界半径:0,
}}
块
>
添加到照片中
当按下按钮时,在IOS中调用downloadFile()函数,但在Android中它不起作用

我还试着像这样在press上登录控制台

          <Button
              onPress={() => console.log("Button Clicked")}
              style={{
                backgroundColor: "#fff",
                width: "60%",
                borderRadius: 0,
              }}
              block
            >

import {TouchableOpacity} from 'react-native-gesture-handler'
console.log(“单击按钮”)}
风格={{
背景颜色:“fff”,
宽度:“60%”,
边界半径:0,
}}
块
>
它在IOS中工作,但在Android中不起作用

另外,如果我像在Android中那样直接在onPress上调用该函数,它会自动记录单击的按钮,而无需按下。我试图找出所有可能的解决方法,但我不知道这个问题的确切原因

         <Button
              onPress={console.log("Button Clicked")}
              style={{
                backgroundColor: "#fff",
                width: "60%",
                borderRadius: 0,
              }}
              block
            >

也许你正面临一个关于android触摸不透明度的问题

您可以从“react native手势处理程序”导入TouchableOpacity,希望这会有很大帮助

你可以这样导入

          <Button
              onPress={() => console.log("Button Clicked")}
              style={{
                backgroundColor: "#fff",
                width: "60%",
                borderRadius: 0,
              }}
              block
            >

import {TouchableOpacity} from 'react-native-gesture-handler'

谢谢你的建议Awais Ibrar,实际上问题在于Android中按钮的位置,因为它没有被按下。没问题。很高兴听到你的问题解决了。