728x90
반응형
TextInputLayout
implementation 'com.google.android.material:material:1.0.0'
xml 코드
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/inputlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:id="@+id/edit_room_name"
android:hint="텍스트가 들어갑니다"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</com.google.android.material.textfield.TextInputLayout>
<Button
android:text="헬퍼"
android:id="@+id/helper"
android:layout_below="@id/inputlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="에러"
android:id="@+id/error"
android:layout_toRightOf="@id/helper"
android:layout_below="@id/inputlayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<Button
android:text="제거"
android:layout_below="@id/inputlayout"
android:layout_toRightOf="@id/error"
android:id="@+id/remove"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</RelativeLayout>
java 코드
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
TextInputLayout inputLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
inputLayout = findViewById(R.id.inputlayout);
findViewById(R.id.helper).setOnClickListener(this);
findViewById(R.id.error).setOnClickListener(this);
findViewById(R.id.remove).setOnClickListener(this);
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.helper:
inputLayout.setHelperText("헬퍼");
break;
case R.id.error:
inputLayout.setError("에러");
break;
case R.id.remove:
inputLayout.setErrorEnabled(false);
break;
}
}
}
실행 화면





TextViewLayout 하나당 EditTextView 하나씩 사용
728x90
반응형
'Android' 카테고리의 다른 글
Android emulator network error - 인터넷 연결 안될때 (0) | 2021.06.29 |
---|---|
Android NavigationView inflate Error 네비게이션 에러 (0) | 2019.10.18 |
Android 리스트뷰 키보드 올라올때 화면 (0) | 2019.10.15 |
Android 그라데이션 (2) | 2019.10.02 |
Android 웹 연결 안될때 (0) | 2019.09.26 |