Pro Android with Kotlin


CHAPTER 9: User Interface


Download 5.42 Mb.
Pdf ko'rish
bet196/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   192   193   194   195   196   197   198   199   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile



247
CHAPTER 9: User Interface
menuInflater.inflate(popup, menu)
show()
}
}
As usual, you also need to define the menu inside the res/menu resources. For the example, 
it’s a file called popup.xml (as shown in the first argument to inflate(...)).
Progress Bars
Showing progress bars is a good way to improve the user experience for tasks that are 
taking a couple of seconds. To implement progress bars, add a ProgressBar view to your 
layout. It doesn’t matter whether you do that inside the XML layout file or from inside the 
Kotlin program. In XML you write the following:
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
for an indeterminate bar (if you can’t tell the progress as a percentage value) or the following 
for a determinate progress bar (you know the percentage while updating the progress bar).
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:progress="0"
/>
Inside the code you toggle the visibility of an indeterminate progress bar by using this:
progressBar.visibility = View.INVISIBLE
// or .. = View.VISIBLE
To set the progress value for a determinate progress bar, see the following example:
with(progressBar) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
min = 0
max = 100
}
var value = 0
Thread {
while(value < 100) {
value += 1
Thread.sleep(200)
runOnUiThread {



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   192   193   194   195   196   197   198   199   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling