[android] TextInputLayout 예제

기본적인 설정은 http://susemi99.kr/3377 를 참고해야 한다.

 

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

  <EditText
      android:id="@+id/edit_user_name"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="User name"
      android:inputType="textEmailAddress"/>
</android.support.design.widget.TextInputLayout>

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

  <EditText
      android:id="@+id/edit_user_password"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:hint="Password"
      android:password="true"/>
</android.support.design.widget.TextInputLayout>

<Button
  android:id="@+id/btn_ok"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:text="OK"/>
final TextInputLayout layoutUserName = (TextInputLayout) findViewById(R.id.layout_user_name);
final TextInputLayout layoutPassword = (TextInputLayout) findViewById(R.id.layout_user_password);
findViewById(R.id.btn_ok).setOnClickListener(new View.OnClickListener()
{
  @Override
  public void onClick(View view)
  {
    layoutUserName.setError("Lorem ipsum dolor sit amet, consectetur adipisicing elit");
    layoutPassword.setError("sed do eiusmod tempor incididunt ut labore et dolore magna aliqua");
  }
});