作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个带有几个表单元素和一个按钮(TouchableHighlight)的 View 。单击该按钮后,事件指示器应显示为现有 View 的覆盖层。事件指示器应位于页面中心,现有 View 应稍微模糊以指示重叠。我尝试了不同的选项,但无法使其正常工作。
render() {
const { username, password } = this.state;
return (
<View style={styles.container}>
<View style={styles.group}>
<Text style={styles.text}>Username:</Text>
<TextInput
style={styles.input}
onChangeText={this.handleUserNameChange.bind(this)}
value={username}
underlineColorAndroid="transparent"
/>
</View>
<View style={styles.group}>
<Text style={styles.text}>Password:</Text>
<TextInput
style={styles.input}
secureTextEntry={true}
onChangeText={this.handlePasswordChange.bind(this)}
value={password}
underlineColorAndroid="transparent"
/>
</View>
<TouchableHighlight
style={styles.button}
onPress={this.handleLogin.bind(this)}>
<Text style={styles.buttonText}>Logon</Text>
</TouchableHighlight>
</View>
);
}
现有样式:
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
backgroundColor: '#F5FCFF',
marginTop: 60
},
group: {
alignItems: 'flex-start',
padding: 10
},
input: {
width: 150,
padding: 2,
paddingLeft: 5,
borderColor: 'gray',
borderWidth: 1
},
text: {
padding: 0
},
button: {
width: 150,
backgroundColor: '#2299F2',
padding: 15,
marginTop: 20,
borderRadius: 5
},
buttonText: {
textAlign: 'center',
color: '#fff',
fontSize: 24
},
});
我需要一个 ActivityIndicator 到上面的 View ,覆盖 View ,并将 ActivityIndicator 居中。
最佳答案
要实现此功能,您需要绝对
定位它,并在应该位于叠加层下方的元素之后渲染它:
loading: {
position: 'absolute',
left: 0,
right: 0,
top: 0,
bottom: 0,
alignItems: 'center',
justifyContent: 'center'
}
然后只需根据加载状态有条件地将其组合到 render
方法中即可。我假设 this.handleLogin 已经设置了某种加载状态。
确保它最后渲染,以便它优先。
...
{this.state.loading &&
<View style={styles.loading}>
<ActivityIndicator size='large' />
</View>
}
关于javascript - 如何在react-native中覆盖ActivityIndicator?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44046500/
我是一名优秀的程序员,十分优秀!