Mobile/Android
[Android] 기본 위젯 사용 예제 2: plain text
춘햄
2022. 3. 14. 08:04
plain text는 입력 상자의 역할을 하는 Edit text이다.
html의 input 태그와 비슷하게 hint 속성을 이용하여 입력 창에 나타날 안내 문구 또한 추가가 가능하며, input type 속성으로 입력 데이터의 타입을 제한할 수 있다.
또한 plain text를 disign palette에서 직접 추가하면, width가 wrap-content일 때 ems = 10이라는 속성이 자동으로 추가가 되는 것을 볼 수 있는데, 이는 해당 위젯의 너비를 EM 단위의 크기로 설정하기 위해 사용한다.
바로 간단한 예제를 하나 생성해보자.
◎strings.xml
<resources>
<string name="app_name">Text_widget_ex_1</string>
<string name="plain_text_hint">이름을 입력해주세요.</string>
</resources>
◎main_activity.xml
<?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">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:hint="@string/plain_text_hint"
android:ems="10"
android:id="@+id/editTextTextPersonName"
/>
</LinearLayout>
반응형