Android新的surpport支持库SurpportDesign之TextInputLayout
来源:互联网 发布:网络黑客的主要行为 编辑:程序博客网 时间:2024/06/05 05:28
TextinputLayout 是一个容器。 他主要是为了处理Edittext 改变Edittext 的样式 ,可以方便提示输入校验信息。提示输入有误或者其他信息
,TextInputLayout 关于是否只能接受一个子元素。我经过实验是不是的。可以有多个元素 。
下面讲下如何使用TExtInputLayout1.添加依赖包 这个 可以查看我上一篇博客 关于Tablaout 已经说的很清楚了
2.xml部分代码
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.yu.viewpagertest.TextInputActivity"> <android.support.design.widget.TextInputLayout android:layout_width="match_parent" android:id="@+id/til" android:layout_height="100dp" app:theme="@style/AppTheme2" > <EditText android:textColor="#000000" android:id="@+id/et" android:layout_width="match_parent" android:layout_height="50dp" android:hint="输入密码" /> </android.support.design.widget.TextInputLayout> </LinearLayout>大家可以看到这里就只是添加了一个 Edittext 但是我在TextInputLayout中添加了一个属性 叫theme 那么这个Theme是干啥的他可以改变Edditext 控件的颜色 下面我贴出 Theme 的代码
<style name="AppTheme2" > <!-- Customize your theme here. --> <item name="colorAccent">#000000</item> </style>这里 colorAccent 就可以设置Edittext的下面的横线的颜色3Java代码 部分
<span style="font-weight: bold; white-space: pre;"></span>final TextInputLayout til= (TextInputLayout) findViewById(R.id.til); EditText et= (EditText) findViewById(R.id.et); et.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { if(s.toString().endsWith("2")){ til.setError(""); }else{ til.setError("輸入有誤"); } } });</pre><pre name="code" class="html"><span style="white-space:pre"></span><span style="white-space:pre"></span>这里就是一个简单的校验 输入有误 然后调用 TextInputLayout 的setError 提示错误信息。 如果输入正确就取消错误提示关于TextInputLayout 的使用方法 我这里也只是一个简单的使用。详细一些的我还没有深入研究。所以大家可以自行深入研究一下。
1 0
- Android新的surpport支持库SurpportDesign之TextInputLayout
- Android新的surpport支持库SurpportDesign之TabLayout
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar的使用
- 新控件之TextInputLayout
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android M新控件之FloatingActionButton,TextInputLayout,Snackbar,TabLayout的使用
- Android进阶——Material Design新控件之TextInputLayout
- Android Design新控件之TextInputLayout(文本输入布局)
- Android Design新控件之TextInputLayout(文本输入布局)
- 【Android - MD】之TextInputLayout的使用
- Windows通过VNC连接Ubuntu
- hbase远程调试
- Android下利用SharePreference存储序列化对象的方法
- matlab 路径下存图片list
- Java没有头文件的原因
- Android新的surpport支持库SurpportDesign之TextInputLayout
- nyoj 71 独木舟上的旅行
- Python(1):在Python 中print的新用法
- 亚马逊新手知识必备
- 【Android】App应用崩溃(Crash/Force Close)之后如何让它自动重启?
- python案例1---修改haproxy的配置文件
- post qt.network.ssl: QSslSocket: cannot resolve SSLv2_client_method解决
- QC登录出现Following client components were not downloaded successfully问题解决
- hadoop2.7.2集群hive-1.2.1整合hbase-1.2.1