In this article, we will explore some common UI components that can be used while developing an application using Jetpack Compose.
Jetpack Compose is the declarative UI approach in native Android app development. It is currently in the pre-alpha stage. This article is the continuation of my previous article.
In Jetpack compose we can build a beautiful layout in a few minutes. It is based on material design principles and provides material design components out of the box.
Compose is built to support material design principles. Many of its UI elements implement material design out of the box.
You might have already heard about Declarative UI with the rise in popularity of Flutter and SwiftUI. Jetpack Compose is the declarative UI approach in native Android app development.
Jetpack Compose was revealed in Google IO 2019. It is still in the development phase and developer preview is available at this time. Many improvements have been made since its launch. It is too early to use in production before the beta version is available. But for early adopters, it is very hard to ignore.
Note: Updated for Android Studio 4.2 Canary 2 and Jetpack Compose Version
Why Jetpack Compose…
In Android, SharedPrefences had always been favorite to store small data but sometimes big too, in a JSON string format.
Today I am going to simplify the data storing and retrieving method via
SharedPreferences in Kotlin way.
Let's start by observing some examples to store/retrieve data from shared preferences.
// get stored value
val myString = prefs.myString// store value
prefs.myString = "My String Value"// get stored array
val myStringArray = prefs.myStringArray// store array
prefs.myStringArray = arrayOf("String 1","String 2","String 3")// store value
prefs.myObject = MyObject("hello")// retrieve my object
val myObject : MyObject? = prefs.myObject
The simplest mistake while writing the toolbar cost me few days.
Make mistakes. Learn from them. Move on. So here goes my first medium post from the mistake I made.
What I did is I wrote following XML code.
Q. What happened after this?
A. I could not set title of the activity by using
setTitle(value) , neither this
setTitle(R.string.value). Since I was starting to play with Kotlin, I thought I might have missed something on the code in activity but problem was different.
Q. Actually what was wrong?
A. The line
app:title="@string/app_name" always set the toolbar title to the
R.string.app_name and this could not be overridden by any means.
Now what I learn from this mistake is that “Never set the toolbar title in XML code”.
Mobile App Developer