利用TextInputLayout实现hint浮动显示(二)
来源:互联网 发布:python怎么发音 编辑:程序博客网 时间:2024/06/05 19:12
- 学习平台:Android Studio2.2.3(基于win8.1 Pro)
- ADT:Nexus 5
- API :24
文章参考自:Creating a Login Screen Using TextInputLayout
先上最终效果图:
接下来是步骤:
1. 新建TextInputLayoutDemo项目
New Project,主activity:LoginActivity,
Layout为login_layout。
2. 添加支持的Library
File–>Project Structure–>app–>添加依赖库。
com.android.support:design:25.0.1
3. 设计Login界面
显示一张图片和一个Welcome,分别靠ImageView和TextView实现 。
两个EditText,分别用于Username和Password。
还有一个用于触发登陆的Button。
下面是login_layout.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" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#e3e3e3" android:orientation="vertical" android:padding="@dimen/activity_horizontal_margin" tools:context=".LoginActivity"> <ImageView android:layout_width="match_parent" android:layout_height="wrap_content" android:src="@drawable/mylogo"/> <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.5" android:orientation="vertical"> <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/username_wrapper" 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/password_wrapper" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/username_wrapper" android:layout_marginTop="4dp"> <EditText android:id="@+id/password" android:layout_width="match_parent" android:layout_height="wrap_content" android:hint="Password" android:inputType="textPassword" /> </android.support.design.widget.TextInputLayout> <Button android:id="@+id/button" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_margin="4dp" android:text="Login" /> </LinearLayout></LinearLayout>
实际上,我做到这一步已经实现了hint的浮动显示,不过原文中还有一步,可能由于我使用的系统恰好可以,但是并非所有的系统到这一步就可以的。所以继续下一步。
4.设置Hints
首先,在setContentView方法下面初始化TextInputLayout视图额引用。
然后,使用setHint方法设置一个hint。
下面是代码:
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.login_layout); final TextInputLayout usernameWrapper = (TextInputLayout) findViewById(R.id.username_wrapper); final TextInputLayout passwordWrapper = (TextInputLayout) findViewById(R.id.password_wrapper); usernameWrapper.setHint("Username"); passwordWrapper.setHint("Password"); }
至此,TextInputLayout实现hint浮动显示就可以了。原文中还有关于条件验证的,我下一篇再继续。
谢谢!
0 0
- 利用TextInputLayout实现hint浮动显示(二)
- 利用TextInputLayout实现hint浮动显示(一)
- android TextInputLayout中的hint显示与重影
- 利用jQuery实现图片信息的浮动显示
- 利用jQuery实现图片信息的浮动显示
- asp.net开发中利用jquery来实现滚动下拉标题浮动固定显示
- Android开发之实现滑动RecyclerView,浮动按钮的显示和隐藏(二)
- TextInputLayout 登录的实现
- 利用jQuary实现文字浮动提示
- 半透明信息显示浮动窗口的实现
- 半透明信息显示浮动窗口的实现
- 半透明信息显示浮动窗口的实现
- 半透明信息显示浮动窗口的实现
- 半透明信息显示浮动窗口的实现
- tr显示hint
- Oracle append Hint(二)
- Android:实现EditText在获得焦点后消去hint,失去焦点后再显示原来的hint
- TextInputLayout
- 玲珑杯-1057-Private Value【思维】【map】
- SqlServer安装遇到的问题几则以及解决办法
- codeforce B. Chloe and the sequence (递归)
- vi/vim基本使用方法
- 【jzoj4922】【环】
- 利用TextInputLayout实现hint浮动显示(二)
- 嵌入式开发中的细节
- 读取文件,到标准输入流(c语言 和 c++版)
- 具有单选标记的菜单;auto关键字;CheckMenuRadioItem函数
- 数据结构-循环链表
- 【ife】任务六:通过HTML及CSS模拟报纸排版
- LeetCode 42. Trapping Rain Water
- 解决macos 10.12下 homebrew 一安装报错问题
- CEPH 分布式存储部署手册 (Ubuntu 14.04)