TextInputLayout的使用
来源:互联网 发布:java base64编码解码 编辑:程序博客网 时间:2024/06/06 17:14
![这里写代码片](http://img.blog.csdn.net/20170721152758132?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQveGlhb3NoaXRvdW5hbg==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast)布局中:<?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:id="@+id/activity_main" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" tools:context="com.example.hello.lianxiday_072102.MainActivity"> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.5" > <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" android:text="Welcome" android:textColor="#333333" android:textSize="30sp" /> </RelativeLayout> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.5" android:orientation="vertical"> <android.support.design.widget.TextInputLayout android:id="@+id/usernameWrapper" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/username" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Username" android:inputType="textEmailAddress" /> </android.support.design.widget.TextInputLayout> <android.support.design.widget.TextInputLayout android:id="@+id/passwordWrapper" android:layout_width="match_parent" android:layout_height="wrap_content" app:hintTextAppearance="@style/errorAppearance" app:errorTextAppearance="@style/hintAppearance" android:layout_marginTop="4dp"> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="shuakjkd是李凯的" android:inputType="textPassword" /> </android.support.design.widget.TextInputLayout> <Button android:id="@+id/btn" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="4dp" android:text="Login" /> </LinearLayout></LinearLayout>Style中: <style name="hintAppearance" parent="TextAppearance.AppCompat"> <item name="android:textSize">14sp</item> <item name="android:textColor">#ffee00</item> </style> <style name="errorAppearance" parent="TextAppearance.AppCompat"> <item name="android:textSize">14sp</item> <item name="android:textColor">#cc0</item> </style>activity中:public class MainActivity extends AppCompatActivity implements View.OnClickListener{ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); findViewById(R.id.btn).setOnClickListener(this); } @Override public void onClick(View v) { TextInputLayout usernameWrapper = (TextInputLayout) findViewById(R.id.usernameWrapper); TextInputLayout passwordWrapper = (TextInputLayout) findViewById(R.id.passwordWrapper); String username = usernameWrapper.getEditText().getText().toString(); String password = passwordWrapper.getEditText().getText().toString(); if (!TextUtils.isEmpty(username)) { usernameWrapper.setError("Not a valid email address!"); } else { usernameWrapper.setErrorEnabled(false); } if (!TextUtils.isEmpty(password) ) { passwordWrapper.setError("Not a valid password!"); } else { passwordWrapper.setErrorEnabled(false); } }}
阅读全文
0 0
- TextInputLayout 的简单使用
- TextInputLayout的使用
- TextInputLayout的使用
- TextInputLayout的使用
- TextInputLayout 的使用
- TextInputLayout的使用
- android TextInputLayout的使用
- TextInputLayout&TextInputEditText的使用
- TextInputLayout的简单使用
- TextInputLayout的使用
- TextInputLayout的使用
- TextInputLayout的使用
- TextInputLayout的使用
- TextInputLayout的简单使用
- TextInputLayout的使用
- Android:TextInputLayout的简单使用
- TextInputLayout的使用坑点
- 【Android-UI】TextInputLayout的使用
- String类、StringBuffer类、StringBuilder类详解
- kotlin实现一个Recyclerview与java的比较
- Quartz任务调度框架学习二(核心接口及cron表达式简介)
- svn“Previous operation has not finished; run 'cleanup' if it was interrupted“报错的解决方法
- 神经网络与深度学习 笔记4 交叉熵代价函数 softmax函数
- TextInputLayout的使用
- 2017.7.17--2017.7.21
- 信息系统手机端
- CentOs 替换yum源为阿里云
- (poj 2588 )Genetic Code
- 解决 3ds Max 载入模型后出现 Missing Dlls 问题
- Docker的使用
- 常用正则表达式
- mysql触发器的学习以及使用