解決react-native軟鍵盤彈出擋住輸入框的問題


這是效果:
代碼:
import React, {Component} from 'react';
import { View, Text, Button, StyleSheet, TextInput, ScrollView, KeyboardAvoidingView, Dimensions } from 'react-native';
import { StackActions, NavigationActions, withNavigation } from 'react-navigation';
const {width, height} = Dimensions.get('window');
class ChangePassword extends Component {
static navigationOptions = {
headerStyle: {
elevation: 0, //去除安卓手機header的樣式
},
};
constructor(props) {
super(props);
this.state = {
isTrue: false,
text: '',
text1: '',
};
}
onChangeText = (text1) => {
this.setState({
text1
},()=> {
if (this.state.text1.length >= 8) {
this.setState({
isTrue: true
})
} else if (this.state.text1.length < 8) {
this.setState({
isTrue: false
})
}
})
}
render() {
return (
<ScrollView style={styles.container}>
<KeyboardAvoidingView behavior="position" keyboardVerticalOffset = {120} >
<Text style={styles.title}>修改密碼</Text>
<Text style={styles.totst}>密碼為8-16位,須包含數(shù)字、字母2中元素</Text>
<TextInput
style={styles.textinput}
placeholder="請輸入初始密碼"
placeholderTextColor = "#cccccc"
maxLength = {16}
value={this.state.value}
secureTextEntry = {true}
onChangeText={(text) => this.setState({text})}
/>
<Text style={styles.Line}></Text>
<TextInput
style={styles.textinput}
placeholder="請輸入新密碼"
placeholderTextColor = "#cccccc"
maxLength = {16}
secureTextEntry = {true}
onChangeText={this.onChangeText}
/>
<Text style={styles.Line}></Text>
{
this.state.isTrue == true ? <Text style={styles.errorconfirm} onPress={() => {
alert('你點擊了確認,該跳轉(zhuǎn)了!~')
// this.props.navigation.navigate('ChangePassword')
}}>確認</Text> : <Text style={styles.confirm}>確認</Text>
}
</KeyboardAvoidingView>
</ScrollView>
);
}
}
const styles = StyleSheet.create({
container: {
height: height,
padding: 16,
},
title: {
color: '#4a4a4a',
fontSize: 23,
fontFamily: 'PingFangSC-Semibold',
},
totst: {
color: '#999999',
fontFamily: 'PingFang-SC-Medium',
fontSize: 13,
marginTop: 16,
},
Line: {
height: 1,
backgroundColor: '#d8d8d8',
},
textinput: {
marginTop: 50,
color: '#4a4a4a',
fontSize: 18,
},
errorconfirm: {
marginTop: 44,
height: 44,
lineHeight: 44,
textAlign: 'center',
fontSize: 16,
color: '#ffffff',
backgroundColor: '#25A3FF',
borderRadius: 4,
},
confirm: {
marginTop: 44,
height: 44,
lineHeight: 44,
textAlign: 'center',
fontSize: 16,
color: '#ffffff',
backgroundColor: '#cccccc',
borderRadius: 4,
}
})
export default withNavigation(ChangePassword);
有無用的代碼,可自行刪除,我不會弄gif的圖 ,要不就配一個圖了。
總結(jié)
以上所述是小編給大家介紹的解決react-native軟鍵盤彈出擋住輸入框的問題,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
用Android?studio實現(xiàn)簡易計算器功能
這篇文章主要為大家詳細介紹了用Android?studio實現(xiàn)簡易計算器功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-05-05
Android4.4+ 實現(xiàn)半透明狀態(tài)欄(Translucent Bars)
這篇文章主要為大家詳細介紹了Android4.4+ 實現(xiàn)半透明狀態(tài)欄,對狀態(tài)欄(Status Bar)和下方導航欄(Navigation Bar)進行半透明處理,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-09-09
Android實現(xiàn)網(wǎng)絡(luò)多線程斷點續(xù)傳下載功能
這篇文章主要為大家詳細介紹了Android實現(xiàn)網(wǎng)絡(luò)多線程斷點續(xù)傳下載功能,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-03-03
Android開發(fā)之PopupWindow創(chuàng)建彈窗、對話框的方法詳解
這篇文章主要介紹了Android開發(fā)之PopupWindow創(chuàng)建彈窗、對話框的方法,結(jié)合實例形式詳細分析了Android使用PopupWindow創(chuàng)建對話框相關(guān)操作技巧,需要的朋友可以參考下2019-03-03
解析Android開發(fā)優(yōu)化之:對界面UI的優(yōu)化詳解(二)
在一個應用程序中,一般都會存在多個Activity,每個Activity對應著一個UI布局文件。一般來說,為了保持不同窗口之間的風格統(tǒng)一,在這些UI布局文件中,幾乎肯定會用到很多相同的布局2013-05-05
Android開發(fā)升級AGP7.0后的一些適配方法技巧
這篇文章主要為大家介紹了升級AGP7.0后的一些適配方法技巧,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-06-06

