、活動。Androidのメーカーは、自動的に私たちのためにMainActivityを作成します。
setContentView(R.layout.activity_main); MainActivityに私たちのためにレイアウトファイルを設定します
パッケージcom.example.helloworld。 輸入androidx.appcompat.app.AppCompatActivity。 輸入android.os.Bundle; パブリック クラス MainActivityは延びAppCompatActivity { @Overrideが 保護 ボイドのonCreate(バンドルsavedInstanceState){ スーパー.onCreate(savedInstanceState)を、 setContentView(R.layout.activity_main)。 } }
二、レイアウト。デフォルトでは、本明細書ConstraintLayout(拘束レイアウト)を使用します。そして、ディスプレイのHello Worldを追加!テキストのTextView
<?XMLバージョン= "1.0"エンコード= "UTF-8" ?> < androidx.constraintlayout.widget.ConstraintLayout のxmlns:アンドロイド= "http://schemas.android.com/apk/res/android" のxmlns:アプリ= "HTTP ://schemas.android.com/apk/res-auto」 のxmlns:ツール= "http://schemas.android.com/tools" のandroid:layout_width = "match_parent" のandroid:layout_height = "match_parent" ツール:コンテキスト= ".MainActivity" > < のTextViewの アンドロイド:layout_width = "wrap_content" のandroid:layout_height = "wrap_content" アプリ:layout_constraintBottom_toBottomOf = "親" アプリ:layout_constraintLeft_toLeftOf = "親" アプリ:layout_constraintRight_toRightOf = "親" アプリ:layout_constraintTop_toTopOf = "親" /> </ androidx.constraintlayout.widget.ConstraintLayout >
三、AndroidManifest.xmlを。このファイルに登録MainActivity
活性は、このコードは、2つの主な活動であるため、以下のように提供されます。アクティビティのエントリは、このアプリを起動します
< アクションアンドロイド:名= "android.intent.action.MAIN" />
< カテゴリアンドロイド:名= "android.intent.category.LAUNCHER" />
<?XMLバージョン= "1.0"エンコード= "UTF-8" ?> < マニフェストのxmlns:アンドロイド= "http://schemas.android.com/apk/res/android" パッケージ= "com.example.helloworld" > < アプリケーション アンドロイド:allowBackup = "true"の アンドロイド:アイコン= "@ミップマップ/ ic_launcher" アンドロイド:ラベル= "@文字列/ APP_NAME" アンドロイド:roundIcon = "@ミップマップ/ ic_launcher_round" アンドロイド:supportsRtl = "true"の アンドロイド:テーマ= "@スタイル/ AppTheme」> < インテントフィルタ> < アクションアンドロイド:名= "android.intent.action.MAIN" /> < カテゴリアンドロイド:名= "android.intent.category.LAUNCHER" /> </ インテントフィルタ> </ アクティビティ> </ アプリケーション> </ マニフェスト>