navigationView = ( <View style={{flex: 1, backgroundColor:'blue'}}> <TouchableOpacity onPress Text style={[styles.textStyle, styles.textSmall]}>从左侧拖出策划菜单</Text> <TouchableOpacity onPress styles.item}> 啦啦啦 </Text> <Text onPress styles.item}> 点点我 </Text> <Text onPress styles.item}> 抱抱我 </Text> <Text onPress
核心源码如下: render() { const { accessibilityLabel, color, onPress, title, ={onPress}> <View style={buttonStyles}> <Text style={textStyles}>{formattedTitle}</ accessibilityLabel是用于盲文的,读屏器软件可能会读取这一内容( colorios表示字体的颜色,android表示背景的颜色 disabled是否可用,如果为true,禁用此组件的所有交互 onPress <Button title='color设置为红色' color='red' /> <Button title='禁用' disabled={true} onPress ToastAndroid.show('点我了'); }}/> <Button title='禁用' onPress
使用范例 // 同时兼容 iOS 和 Android Alert.alert( '弹出框标题', '弹出框描述', [ {text: '自定义按钮', onPress: () => console.log('点击了自定义按钮')}, { text: '取消', onPress: () => console.log('点击了取消按钮'), style: 'cancel', }, {text: '确认', onPress: () => console.log('点击了确认按钮')}, ], {cancelable: , [ {text: '确认', onPress: () => showTip()}, {text: '取消', , [ {text: '取消', style: 'cancel'}, {text: '确认', onPress:
<Button style = {styles.homeBtnStyle} title = "Go to detail" onPress this.props.navigation.push('Details')} /> <Button title = "Go to home" onPress this.props.navigation.navigate('Home')} /> <Button title = "Go back" onPress , [ {text: '确定', onPress: () => this.props.navigation.goBack()}, {text: '取消', onPress: () => console.log('Cancel Pressed'), style: 'cancel'} ]
<DrawerContentScrollView> <Text>自定义抽屉的内容</Text> <Button title="跳转到详情" onPress { props.navigation.navigate("Detail", { id: 123 }) }}></Button> <Button title="跳转到个人中心" onPress id: 123 //传递参数 }) } return ( <View> <Button title="打开抽屉" onPress ={() => props.navigation.openDrawer()}></Button> <Button title="跳转到详情" onPress={() => goDetail ()}></Button> <Button title="跳转到生命周期函数" onPress={() => props.navigation.navigate("Life")}
简单UI(XView,XText,XImage) 1、事件支持 View,Text,Image作为使用频率最高的三个组件,并不支持我们最常使用的onPress事件,我们要使用onPress事件时,得使用 X系列组件的使用使得这三个基本组件支持onPress事件,实现原理很简单,若传入的属性中包含onPress方法,则返回一个由Touchable系列组件(默认为:TouchableOpacity)包裹的组件 console.log('点击了图片')} icon='img_click.png' iconSize={20}/> <XImage style={styles.imageStyle} onPress ={() => console.log('点击了View')} icon='img_click.png'/> <XView style={styles.imageStyle} onPress ={() => console.log('点击了文本')}/> <XText style={styles.textStyle} onPress={() => console.log('点击了文本
tabNomal}/>} renderSelectedIcon={()=><Image style={styles.icon} source={tabPress}/>} onPress ={()=>this.onPress(tabName)} renderBadge={()=>isBadge? tabNomal}/>} renderSelectedIcon={()=><Image style={styles.icon} source={tabPress}/>} onPress ={()=>this.onPress(tabName)} renderBadge={()=>isBadge? ={()=>this.onPress(tabName)} renderBadge={()=>isBadge?
它获取android SDK提供的com_example_android_softkeyboard例子程序,然后,修改OnPress() public void onPress(int primaryCode LatinKeyboard)currentKeyboard; iKeyboardResId = CurrentKeyboard.mXmlResId; //Log.d("XL: onPress //iCode = parser.getAttributeIntValue(0, -1); //Log.d("XL: onPress keyCode",String.valueOf(iCode)); //Log.d("XL: onPress keyCode primaryCode keyCode",String.valueOf(iCode)); //Log.d("XL: onPress keylabel", sLabel
left' verticalOrientation='up'> <ActionButton.Item buttonColor='#9b59b6' title="New Task" onPress </ActionButton.Item> <ActionButton.Item buttonColor='#3498db' title="Notifications" onPress </ActionButton> <ActionButton buttonColor="rgba(231,76,60,1)" onPress size:按钮的大小,默认为56 active:是否显示按钮 position:按钮的位置,可以为left center right offsetX:X轴上的偏移位置 offsetY:Y轴上的偏移位置 onPress down renderIcon:可以自定义按钮显示的样式,默认是一个加号 ActionButton.Item size:按钮的大小,默认为56 title:按钮标题 buttonColor:按钮颜色 onPress
banner }) => ( <ScrollView> <SampleText>{banner}</SampleText> <Button // 界面之间传值 onPress > navigation.navigate('Profile', { name: 'Jordan' })} title="去第一个页面" /> <Button onPress ={() => navigation.navigate('TwoPage')} title="去二级页面" /> <Button onPress={() => navigation.navigate ('MinePage')} title="去我的页面" /> <Button onPress={() => navigation.goBack(null)} title="返回
御用导航” 但是在使用过程中还是发现了一个问题:在触发页面跳转的View上 重复、快速点击时,即将被加载的页面会多次被加载(感谢测试小姐姐丧心病狂的操作),症状如下图 分析问题 经过观察发现,在onPress 显然,页面跳转时,并未对事件进行控制,只要触发,就会加载新的页面 解决方案 既然源码未加控制,我们就手动加上,目前思路有2种 – 普通版 在onPress事件处控制,第一次点击后,加上延时,禁止之后的点击操作 this.state.waiting控制TouchableOpacity的disabled属性 <TouchableOpacity disabled={ this.state.waiting} onPress 此时onPress事件无需再加控制 <TouchableOpacity // disabled={this.state.waiting} onPress={() => this.props.navigation.navigate
_onUnhighlight} onPress={this.props.onPress} onShowUnderlay={this. </Text> <Button onPress={this. activeButtonStyle : {}}> none </Button> <Button onPress={this. activeButtonStyle : {}}> slide </Button> <Button onPress={this. _toggleTransparent} /> </View> <Button onPress={this.
自定义方法,改变title的值 _gotoPage(title) { this.props.navigation.setParams({title: title}); } 使用onPress 调用方法 onPress={this. _gotoPage.bind(this, '消息')} 或者方便起见,也可以不定义方法,直接在onPress中调用: onPress={() => this.props.navigation.setParams
console.log(res) }) } return ( <View> <Button title="启动图库选择图像" onPress ={() => addPhoto()}></Button> <Button title="启动图库选择视频" onPress={() => addVideo()}></Button > <Button title="启动相机拍摄图片" onPress={() => tackPhoto()}></Button> {
</Text> </TouchableOpacity> <TouchableOpacity style={styles.action} onPress = () => { props.onSelect(props.index); } return ( <TouchableWithoutFeedback onPress ={onPress}> <View style={styles.item}> <Text style={props.selected ? (props.index, props.subindex, props.data); } return ( <TouchableHighlight onPress={onPress [styles.tableItemText, styles.highlight] : styles.tableItemText; let onPress = () => {
64 : 44) renderBtn(pos){ let render = (obj) => { const { name, onPress } = obj if(Platform.OS === 'android'){ return ( <TouchableNativeFeedback onPress={onPress TouchableNativeFeedback> ) }else{ return ( <TouchableOpacity onPress ={onPress} style={styles.btn}> <Icon name={name} size={px2dp(26)} color="#fff" /> (this.props.leftIcon){ return render({ name: this.props.leftIcon, onPress
={this.addItem}>增加</Text> <Text style={styles.addItem} onPress={this.deleteItem}>删除</ item.name}</Text> <Text>{item.count}</Text> <Text style={styles.btn} onPress ={this.countAdd}> + </Text> <Text style={styles.btn} onPress={this.countDec}> - </Text style={styles.itemContainer}> <Text style={styles.item} onPress this.updateNewItem(text)} style={styles.input} /> <TouchableHighlight onPress
onPress function 当触摸操作结束时调用,但如果被取消了则不调用(譬如响应者被一个滚动操作取代)。 心得:onPress可谓是Touchable系列组件的最常用的属性之一了,如果你要让视图响应用户的单击事件,那么用onPress就可以了。 接下来呢,我们就来使用onPress属性来实现一个统计按钮单击次数的例子。 <TouchableWithoutFeedback onPress={()=> { this.setState({count: this.state.count+1}) 心得:当我们没有对Touchable组件设置onLongPress属性而设置了onPress属性的时候,我们长按按钮之后会回调onPress方法。
Text style={styles.counter}>{this.state.count}</Text> <TouchableOpacity style={styles.reset} onPress <Text>归零</Text> </TouchableOpacity> <TouchableOpacity style={styles.start} onPress <Text>加1</Text> </TouchableOpacity> <TouchableOpacity style={styles.stop} onPress <Text>归零</Text> </TouchableOpacity> <TouchableOpacity style={styles.start} onPress <Text>加1</Text> </TouchableOpacity> <TouchableOpacity style={styles.stop} onPress
下面拿Image的source属性和Text的onPress属性作为举例。 Text的onPress属性 接着拿我们熟悉的Text来做举例,如下所示。 Alert.alert('弹出框'); }; AppRegistry.registerComponent('firstProject', () => TextPressApp); 注释1处的onPress 就是Text的属性,除了onPress,Text还有很多其他的属性,比如numberOfLines、onLayout和style等等。 render() { return ( <View>//2 <Text style={styles.largeblue} onPress