Android(kotlin) 初めての画面作成
この記事は、Kotlin で Android アプリ開発 内の一つの記事です。
Android アプリ開発の画面作成を学ぶために、取りあえずプロジェクトを作成してみます。
プロジェクトの作成
Empty Activity を選んでいきます。
プロジェクト名などは適当に設定します。
自分は "View Practice" と設定しています。
strings.xml に文字列情報を追加する
res/values/strings.xml
画面に表示する文字列を設定するために以下のように記述します。
<resources> <string name="app_name">View Practice</string> <string name="in_msg">Input your name</string> </resources>
レイアウトファイルの編集
res/layout/activity_main.xml
初期では ConstraintLayout が設定されていますが、分かり易い LinearLayout で書き直しします。
<?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:background="#000000" android:orientation="vertical" > <TextView android:id="@+id/inLabelInput" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="10dp" android:layout_marginTop="5dp" android:background="#ffffff" android:text="@string/in_msg" android:textSize="25sp"/> </LinearLayout>