Antonio Leiva
Time:Mar 9,
Original link:https://antonioleiva.com/dialogs-android-anko-kotlin/
with Builder, creating warning tips and dialogs on Android is relatively simple, but because of the complexity of the language, some hints often become very vague.
in the in Kotlin, only Lambda Expressions can help us understand a little bit about how the code is handled.
However, with the Anko, we can make it all easier, and in this article we see what's going on.
in the Kotlin use Anko as a warning tip.
through Anko Writing warning tips is very easy. You only need to create an alert code block:
1 alert ("Testing Alerts") {2 ... 3 }.show ()
In this block of code, you can specify something, such as the title of the hint, or the button you want to display:
1 alert ("Testing Alerts") {2 title ("Alert")3 Yesbutton {toast ("Yess!!!" )}4 Nobutton {}5 }.show ()
The result of this piece of code is this:
You can also use positiveButton
, negativeButton
and the neutralButton
method to customize some actions:
1 alert ("Testing Alerts") {2 title ("Alert")3 Positivebutton ( "Cool") {toast ("Yess!!!" )}4 Negativebutton ("Never Ever") {}5 Neutralbutton ("I ll think About it ")6 }.show ()
of course, you can even pass Anko Custom Views:
1 Alert {2Title ("Alert")3Positivebutton ("Cool") {toast ("Yess!!!") }4 CustomView {5 LinearLayout {6TextView ("I ' m a text")7button ("I ' m a button")8padding = Dip (16)9 }Ten } One}.show ()
Progress dialog Box
Anko There is another feature that allows you to create a progress dialog box, and an indeterminate progress.
Here is a second example where you can create a progress dialog box in such a simple way:
1 indeterminateprogressdialog ("This a progress dialog"). Show ()
The results are as follows:
Conclusion
as a result of Anko and Kotlin, as you can see, creating a small DSL is an easy thing to do. Ideally, you can create a DSL in any part of the framework , so it makes the interaction very easy.
in the later in the article , we explain how to process the database through SQLite .
now, is it time to read Free usage guide to Learn how to build your first project? or read a book and learn how to create a complete application from scratch?
Use Anko and Kotlin to implement dialog boxes and warning prompts on Android (KAD 24)