textInputLayout使用简介

TextInputLayout使用简介

通常使用输入框时都会给出提示信息,但是当用户开始输入时,提示信息就会消失,从Android 5.0开始,google提供了一个新的控件来完善EditText的用户体验,先上效果图。

TextInputLayout效果图

使用TextInputLayout,首先需要在gradle中添加依赖,打开build.gradle(Module:app),在dependencies块中添加如下内容

 compile 'com.android.support:appcompat-v7:25.3.1'
 compile 'com.android.support:design:25.3.1' 

建议使用24以上的版本,否则将导致有些熟悉无法正常使用。

TextInputLayout继承自LinearLayout,他里面只能包含一个子控件,通常是EditText,接下来看看布局文件中应该如何使用:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
                xmlns:app="http://schemas.android.com/apk/res-auto"
                android:background="@color/login_bg"
                tools:context="com.example.tom.visitshop.activity.LoginActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginTop="@dimen/login_LinearLayout_margin_top"
            android:orientation="vertical">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:src="@mipmap/login_guide"/>


            <android.support.design.widget.TextInputLayout
                android:id="@+id/et_name_design"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:counterMaxLength="16"
                app:counterEnabled=
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值