React Native - TextInput详细解说
1,TextInput组件介绍
2,组件的属性
3,组件的方法
4,使用样例
- 页面上添加一个 TextInput 用于输入文字,并设置相关的占位符文字以及样式。
- 当输入框文字改变时,下方 Text 组件会实时统计并显示输入的文字长度。
- 点击输入框右侧“搜索”按钮,则将输入框内容弹出显示。
(2)样例代码
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
import React, { Component } from 'react';import { AppRegistry, StyleSheet, Text, View, TextInput,} from 'react-native';//输入框组件class Search extends Component { //构造函数 constructor(props) { super(props); this.state = {text: ''}; } //组件渲染 render() { return ( <View style={styles.flex}> <View style={[styles.flexDirection, styles.inputHeight]}> <View style={styles.flex}> <TextInput style={styles.input} returnKeyType="search" placeholder="请输入关键字" onChangeText={(text) => this.setState({text})}/> </View> <View style={styles.btn}> <Text style={styles.search} onPress={this.search.bind(this)}>搜索</Text> </View> </View> <Text style={styles.tip}>已输入{this.state.text.length}个文字</Text> </View> ); } //搜索按钮点击 search(){ alert("您输入的内容为:"+this.state.text); }}//默认应用的容器组件class App extends Component { render() { return ( <View style={[styles.flex, styles.topStatus]}> <Search></Search> </View> ); } }//样式定义const styles = StyleSheet.create({ flex:{ flex: 1, }, flexDirection:{ flexDirection:'row' }, topStatus:{ marginTop:25, }, inputHeight:{ height:45, }, input:{ height:45, borderWidth:1, marginLeft: 5, paddingLeft:5, borderColor: '#ccc', borderRadius: 4 }, btn:{ width:55, marginLeft:-5, marginRight:5, backgroundColor:'#23BEFF', height:45, justifyContent:'center', alignItems: 'center' }, search:{ color:'#fff', fontSize:15, fontWeight:'bold' }, tip:{ marginLeft: 5, marginTop: 5, color: '#C0C0C0', }});AppRegistry.registerComponent('HelloWorld', () => App); |
原文出自:www.hangge.com 转载请保留原文链接:http://www.hangge.com/blog/cache/detail_1526.html
React Native - TextInput详细解说的更多相关文章
- react native TextInput
今天我想说一下react native中的一个控件,TextInput 翻译过来就是文本输入,对应着android中的EditText.我们先看一下官方是怎样描述的.TextInput是一个允许用户在 ...
- React Native 之 TextInput使用
前言 学习本系列内容需要具备一定 HTML 开发基础,没有基础的朋友可以先转至 HTML快速入门(一) 学习 本人接触 React Native 时间并不是特别长,所以对其中的内容和性质了解可能会有所 ...
- React Native 组件之TextInput
React Native 组件之TextInput类似于iOS中的UITextView或者UITextField,是作为一个文字输入的组件,下面的TextInput的用法和相关属性. /** * Sa ...
- React Native控件只TextInput
TextInput是一个允许用户在应用中通过键盘输入文本的基本组件.本组件的属性提供了多种特性的配置,譬如自动完成.自动大小写.占位文字,以及多种不同的键盘类型(如纯数字键盘)等等. 比如官网最简单的 ...
- react native 封装TextInput组件
上一篇 react-native文章提到了TextInput组件对安卓的适配问题,因此对该组件进行封装很有必要. 文章地址 react native定报预披项目知识点总结 TextInput介绍 官 ...
- React Native之TextInput的介绍与使用(富文本封装与使用实例,常用输入框封装与使用实例)
React Native之TextInput的介绍与使用(富文本封装与使用实例,常用输入框封装与使用实例) TextInput组件介绍 TextInput是一个允许用户在应用中通过键盘输入文本的基本组 ...
- React Native(十三)——ios键盘挡住textInput
渐入佳境 用React Native重构的项目也快接近尾声,剩下的就是适配ios的功能了.慢慢地也从中琢磨出了一点门道,于是就遇见了键盘遮挡textInput问题斑斑: 正常页面: android点击 ...
- [RN] React Native 键盘管理 在Android TextInput遮盖,上移等问题解决办法
React Native 键盘管理 在Android TextInput遮盖,上移等问题解决办法 解决办法: 打开android工程,在AndroidManifest.xml中配置如下: <ac ...
- [React Native]高度自增长的TextInput组件
之前我们学习了从零学React Native之11 TextInput了解了TextInput相关的属性. 在开发中,我们有时候有这样的需求, 希望输入区域的高度随着输入内容的长度而增长, 如下: 这 ...
随机推荐
- NodeJS开发环境配置
"Node.js 是服务器端的 JavaScript 运行环境,它具有无阻塞(non-blocking)和事件驱动(event-driven)等的 特色,Node.js 采用 V8 引擎,同 ...
- Silverlight中使用MVVM(1)--基础
Silverlight中使用MVVM(1)--基础 Silverlight中使用MVVM(2)—提高 Silverlight中使用MVVM(3)—进阶 Silverlight中使用MVVM(4)—演练 ...
- mongodb备份策略
概述 数据库的备份非常非常非常重要!!!否则出问题连哭的机会有没有(欲哭无泪)今天主要是做一个mongodb的数据库备份. 1.关于备份 备份其实很简单,这里选择的是对mongodb中的某个库进行全备 ...
- gradle 转 maven
1. 预备 1.1. java 环境 验证 java -version 1.2. gradle 安装, 参考, 这里列举下windows下的安装 b.1 下载包:https://gradle.org/ ...
- 小程序获取view元素的高度
页面wxml <!--page/index/index.wxml--> <view id='demo'> <text>哈哈哈哈哈</text> < ...
- KMP算法(——模板习题与总结)
KMP算法是一种改进的模式匹配算法,相比于朴素的模式匹配算法效率更高.下面讲解KMP算法的基本思想与实现. 先来看一下朴素模式匹配算法的基本思想与实现. 朴素模式匹配算法的基本思想是匹配过程中如果该位 ...
- Netty 接受请求过程源码分析 (基于4.1.23)
前言 在前文中,我们分析了服务器是如何启动的.而服务器启动后肯定是要接受客户端请求并返回客户端想要的信息的,否则要你服务器干啥子呢?所以,我们今天就分析分析 Netty 在启动之后是如何接受客户端请求 ...
- Android studio删除工程项目
本新手最近学Android都是用的eclipse.其实个人觉得eclipse不错,可能接触Android不久,倒也不觉得它慢还是怎样.对于Google的Android studio也是早有耳闻,前两天 ...
- thinkphp ajax删除 隐藏与显示
知识点: 1.ajax删除: 2.一个同步实现三个异步的效果. html 部分 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transit ...
- 【CentOS7】CentOS 7 安装 MySQL
转自:http://www.centoscn.com/mysql/2016/0315/6844.html 环境 CentOS 7.1 (64-bit system) MySQL 5.6.24 Cent ...