Lesson 4 Build Your First Android App
Lesson 4 Build Your First Android App
● Activity
● Resources (layout files, images, audio files, themes, and
colors)
● Gradle files
<TextView
android:layout_width="wrap_content"
Hello World!
android:layout_height="wrap_content"
android:text="Hello World!"/>
The ViewGroup is the parent and the views inside it are its children.
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Hello World!"/>
</FrameLayout> This work is licensed under the
Android Development with Kotlin Apache 2 license. 24
LinearLayout example
● Aligns child views in a row or column
● Set android:orientation to horizontal or vertical
<LinearLayout
TextView
android:layout_width="match_parent"
TextView
android:layout_height="match_parent"
android:orientation="vertical">
Button
<TextView ... />
<TextView ... />
<Button ... />
</LinearLayout> This work is licensed under the
Android Development with Kotlin Apache 2 license. 25
View hierarchy
LinearLay
out ImageView
Butt Butt
on on
Button Button
main
├── java
└── res
├── drawable
├── layout
├── mipmap
└── values
Within your app, you can now refer to this specific TextView using:
R.id.helloTextView
onCreate()
App is running
Activity shut
down
ViewGrou
p
Layout files LayoutInflat
View1 ViewGrou
layout1 layout2 layout3 er
p
View2 View3
Within MainActivity.kt:
An event is
fired
init {
// retrieve records given an id
}
}
● Declare plugins
● Define Android properties
● Handle dependencies
● Connect to repositories
defaultConfig {
applicationId "com.example.sample"
minSdkVersion 19
targetSdkVersion 30
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-
jdk7:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.2.1'
...
}
repositories {
google()
jcenter()
maven {
url "https://maven.example.com"
}
}
● Clean
● Tasks
● InstallDebug
<ImageView
...
android:contentDescription="@string/stop_sign" />