社内se × プログラマ × ビッグデータ

プログラミングなどITに興味があります。

Android(kotlin) EditText を追加する

この記事は、Kotlin で Android アプリ開発 内の一つの記事です。
EditText(入力ボックス)を画面内に配置してみます。

レイアウトファイルの編集

res/layout/activity_main.xml

<EditText
        android:id="@+id/etInput"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="25dp"
        android:layout_marginTop="10dp"
        android:background="#ffffff"
        android:inputType="text"/>

android:layout-width/height はすべての画面部品に記述する必要があります。
50dp のように数値を指定することも可能です。
よく指定されるのが、"match_parent" と "wrap_content" です。

"match_parent" を指定すると、親部品のサイズいっぱいまで、その部品のサイズが拡張されます。
"wrap_content" を指定すると、その部品の表示に必要なサイズに自動的に調整されます。

android:layout_height="wrap_content" の場合

f:id:blueskyarea:20200405133931p:plain
edit_text1

android:layout_height="match_parent" の場合

f:id:blueskyarea:20200405133953p:plain
edit_text2

エミュレータ上で起動し入力ボックスをタッチしてみると、キーボードが表示され入力することが可能です。

f:id:blueskyarea:20200405134015p:plain
edit_text3
次回はデザインモードについて学んでいきます。