Skip to main content

Posts

android kotlin - Popup window example

Popup Window The PopupWindow class represents a popup window. The PopupWindow class is used to display an arbitrary view. The popup window is a floating container and it appears on top of the current activity. The following android application development tutorial will demonstrate to us how we can create and display a popup window in an application. We used the Kotlin programming language to write the code for this tutorial. We also applied the enter and exit transition for the popup window. To show a popup window on top of the current activity, at first we create a custom view. Using the LayoutInflater we inflate the custom view. Then we create a new instance of PopupWindow with this inflated view. We also define the popup window width and height in this constructor. We set an elevation for the Popup window so it looks natural on top of the activity. We create an enter and exit animation for the popup window transitions. So the popup wi...

android kotlin - ProgressBar example

MainActivity.kt package com.cfsuman.kotlintutorials import android.app.Activity import android.os.Bundle import android.os.Handler import android.os.Looper import android.widget.Button import android.widget.ProgressBar import android.widget.TextView class MainActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // Get the widgets reference from XML layout val button = findViewById<Button>(R.id.button) val textView = findViewById<TextView>(R.id.textView) val progressBar = findViewById<ProgressBar>(R.id.progressBar) // Variable to hold progress status var progressStatus = 0; // Initialize a new Handler instance val handler: Handler = Handler(Looper.getMainLooper()) // Set a click listener for button widget button.setOnClickListener{ // Disable the button itse...

android kotlin - GridView example

MainActivity.kt package com.cfsuman.kotlintutorials import android.app.Activity import android.os.Bundle import android.widget.* class MainActivity : Activity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) // get the widgets reference from XML layout val gridView = findViewById<GridView>(R.id.gridView) val textView = findViewById<TextView>(R.id.textView) // Initialize a list of string values val colors = listOf<String>( "Red","Green","Yellow","Blue", "Magenta","Pink","White","Gray" ) // Initialize a new array adapter instance val adapter = ArrayAdapter( this, // Context android.R.layout.simple_list_item_1, // Layout colors // List ) // Set the ...

android kotlin - SeekBar example

Kotlin SeekBar The SeekBar is a native android SDK widget. The SeekBar widget is an extension of android SDKs ProgressBar widget. SeekBar adds a druggable thumb to the ProgressBar to build itself. Android app users can touch the SeekBar thumb and drag left or right to set the current progress level. They also can tap on SeekBar to select the specified position value. The following android kotlin tutorial will demonstrate how we can add a SeekBar widget to our app. And how we can allow users to select a value using the SeekBar component. The SeekBar.onSeekBarChangeListener is an interface for SeekBar widget. This callback notifies clients when the progress level has been changed. So, we can handle the SeekBar progress change events using this interface. We can do some tasks when the app user changes the SeekBar value. The SeekBar progress level is in the range of min and max. Android developers can set the SeekBar minimum and maximum values. Android SDK al...

android kotlin - Switch button example

Switch Button The following kotlin tutorial will demonstrate to us how we can use a Switch button in an android application. And how we can implement the Switch button checked change listener using the kotlin programming language. We used the SwicthCompat widget in this tutorial instead the Switch/SwitchMaterial widget. Android Developers also can use the SwitchMaterial widget instead the Switch/SwicthCompat widget. The SwitchMaterial widget used attributes from the material theme. The SwitchMaterial behaves identically to the SwitchCompat widget. The SwicthCompat is a complete backport of the core Switch widget. The SwitchCompat widget brings the visuals and functionality of the Switch widget to older versions of the android platform. We have to put the SwicthCompat widget in our XML layout file to use it instead Switch button in an android application. We have to explicitly use the SwicthCompat widget. Android application developers can change the Switc...

android kotlin - ToggleButton example

ToggleButton The following kotlin tutorial will demonstrate to us how we can use a ToggleButton in an android application. And how we can implement the ToggleButton checked change listener using the kotlin programming language. We used the standard ToggleButton widget in this tutorial instead the AppCompatToggleButton widget. The AppCompatToggleButton is a ToggleButton that supports compatible features on older versions of the android platform. Android application developers can tint the ToggleButton background color and drawable color. We can tint both the background and drawable color using API methods and XML attributes. Developers can display an icon on the ToggleButton surface in different positions. App developers can set the ToggleButton’s on and off states text using both XML attributes and API methods.Developers also can initially check or uncheck (On or Off) a ToggleButton using both XML attribute and API method. The Togg...

android kotlin - ListView example

Kotlin ListView The ListView is a list widget of android native SDK. The ListView widget displays a vertically scrollable collection of views. Each view represents a list item. And each view is positioned immediately below the previous view. The listVIew is used to display a simple list of items. The following android tutorial will demonstrate to us how we can use a ListView widget in an android application using the Kotlin programming language. Here we will display a simple list of items inside the ListView widget and also implement the item click handler. Android developers can easily add a ListView widget using the ListView tag to an XML layout file. The ListView tag has several useful attributes to tweak a ListView configuration such as divider, dividrHeight, entries, etc. The ListView ‘entries’ attribute reference an array resource that will populate the ListView with items. The ‘divider’ attribute value may be a drawable or color to draw between lis...