这将是向我抛出错误的组件。具体来说就是 TextInput。我尝试将其从组件中删除,错误消失了。
import { Formik } from "formik";
import { Button, TextInput, View } from 'react-native';
import { FormValues } from "./types";
import Box from "../../../../components/Box";
const Form = (): JSX.Element => {
const initialValues: FormValues = {
first_name: "",
last_name: "",
email: "",
password: "",
github_profile: "",
linkedin_profile: ""
}
const onSubmit = () => {
// handle submit
}
return (
<Box style={{flex: 1, backgroundColor: 'black'}}>
<Formik
initialValues={initialValues}
onSubmit={onSubmit}
>
{({ handleChange, handleBlur, handleSubmit, values }) => (
<View>
<TextInput
onChangeText={handleChange('email')}
onBlur={handleBlur('email')}
value={values.email}
/>
<Button onPress={() => handleSubmit()} title="Submit" />
</View>
)}
</Formik>
</Box>
)
}
export default Form;
这将是我的 launch_screen 文件:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView android:layout_width="match_parent" android:layout_height="match_parent" android:src="@drawable/launch_screen" android:scaleType="centerCrop" />
</RelativeLayout>
最佳答案
我也遇到了这个错误。就我而言,发生这种情况是因为我指向 styles.xml 中的 XML 文件。
styles.xml 文件:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<!-- Customize your theme here. -->
<!-- This line was creating the issue. So, I comment it. -->
<!-- <item name="android:editTextBackground">@layout/launch_screen</item> -->
<item name="android:windowBackground">@drawable/coldscreen</item>
<item name="android:statusBarColor">
@android:color/transparent
</item>
</style>
评论后,我从 android studio 中清理了该项目,从我的移动设备中删除了该应用程序,然后再次在 Visual Code 中运行该项目。
launch_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/screen"
android:scaleType="centerCrop"
android:contentDescription="@string/todo" />
</RelativeLayout>
我的注册屏幕在使用 TextInput 时发生错误。我向你展示我的返回函数。评论该行后,我的应用程序运行良好。我希望这对您有所帮助。
SignUp.tsx
<View style={styles.mainContainer}>
<Text style={styles.Heading}>SignUp</Text>
<View>
<TextInput
value='sadas'
placeholder='Enter email...'
placeholderTextColor={'lightgray'}
style={{backgroundColor: 'red', borderRadius: 10, borderWidth: 1}}
/>
</View>
</View>
关于android - TextInput 和 launch_screen 文件中的relativelayout错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76773115/