TextInputLayout 用法

 

 

 

 

 

 

 

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >
    
    <!--只能有一个子控件,必须是edit-->
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:id="@+id/tl_username"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="用户名"
            android:maxLength="25"
            android:maxLines="1"
            />

    </android.support.design.widget.TextInputLayout>
    <android.support.design.widget.TextInputLayout
        android:layout_width="match_parent"
        android:id="@+id/tl_password"
        android:layout_height="wrap_content">

        <android.support.design.widget.TextInputEditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="密码"
            android:maxLength="25"
            android:maxLines="1"
            android:inputType="textPassword"
            />

    </android.support.design.widget.TextInputLayout>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="登录"
        android:layout_gravity="center_horizontal"
        android:id="@+id/btnLogin"
        />

</LinearLayout>
package com.xiaozhuyisheng.jinjiedemos.activity;

import android.support.design.widget.TextInputLayout;
import android.view.View;

import com.xiaozhuyisheng.jinjiedemos.BaseActivity;
import com.xiaozhuyisheng.jinjiedemos.R;

import butterknife.BindView;

public class TextInputLayoutDemoActivity extends BaseActivity {

    @BindView(R.id.tl_password)
    TextInputLayout tl_password;

    @Override
    protected int initLayoutID() {
        return R.layout.activity_text_input;
    }

    @Override
    protected void initLogic() {

        findViewById(R.id.btnLogin).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                tl_password.setError("密码错误");
            }
        });
    }
}

 

posted @ 2019-02-18 17:06  疯子FK  阅读(1456)  评论(0编辑  收藏  举报