Android Basics with Compose an online course by Google
…
fun main() { println("Hello, world!") }
main function as the entry point of the program.fun keyword, followed by the name of the function, any inputs enclosed in parentheses, followed by the function body enclosed in curly braces.val count: Int = 2
Type inference:
val count = 2
If you need to update the value of a variable, declare the variable with the Kotlin keyword var, instead of val:
var cartTotal = 0
cartTotal = 20
println("Total: $cartTotal")
val keyword to define a variable that is read-only where the value cannot change once it's been assigned.var keyword to define a variable that is mutable or changeable.val over var when possible.val or var keyword. Then specify the variable name, data type, and initial value. For example: val count: Int = 2Int, String, Boolean, Float, and Double.=) to assign a value to a variable either during declaration of the variable or updating the variable.var).++) or decrement operator (–) to increase or decrease the value of an integer variable by 1, respectively.+ symbol to concatenate strings together. You can also concatenate variables of other data types like Int and Boolean to Strings.fun main() { val numberOfPhotos = 100 val photosDeleted = 10 println("$numberOfPhotos photos") println("$photosDeleted photos deleted") println("${numberOfPhotos - photosDeleted} photos left") }
By default, if you don't specify a return type, the default return type is Unit. Unit means the function doesn't return a value (equivalent of void in other languages).
Any function that doesn't return a value implicitly returns Unit.
birthdayGreeting(name="Rex", age=2) // the same: birthdayGreeting(age=2, name="Rex")
fun birthdayGreeting(name:String="Rex", age:Int): String { // function body here... } // call function with two parameters birthdayGreeting("Rex", 2) // call function with only one parameter, but delivers the same result: birthdayGreeting(age=2)
…
More Kotlin exercises can be found in Kotlin Core track by JetBrains Academy.
(Optional video)
…
…
…
setContent() function within the onCreate() function is used to define your layout through composable functions. All functions marked with the @Composable annotation can be called from the setContent() function or from other Composable functions. The annotation tells the Kotlin compiler that this function is used by Jetpack Compose to generate the UI.@Composable annotation before the function.@Composable function names are capitalized.@Composable functions can't return anything.GreetingPreview() function is a cool feature that lets you see what your composable looks like without having to build your entire app. To enable a preview of a composable, annotate with @Composable and @Preview. The @Preview annotation tells Android Studio that this composable should be shown in the design view of this file.…
@Composable annotation before the function, @Composable functions can't return anything.Modifier is used to augment or decorate your composable.…
…
(Optional video)
(Optional video)
https://developer.android.com/codelabs/basic-android-kotlin-compose-text-composables
@Composable annotation. @Preview@Preview(showBackground = true)…
…
Box, Column, Row etc…
Row(
content = {
Text("Some text")
Text("Some more text")
}
)
// the same in trailing lambda syntax:
Row {
Text("Some text")
Text("Some more text")
}
…
…
Box layout to stack elements on top of one another. ContentScale.Crop parameter scaling, which scales the image uniformly to maintain the aspect ratio so that the width and height of the image are equal to, or larger than, the corresponding dimension of the screen.…
…
https://developer.android.com/courses/android-basics-compose/unit-3
…
…
…
…
…