Found 2041 Articles for Mobile Development

How to handle the click event in Listview in Android using Kotlin?

Azhar
Updated on 18-Aug-2020 11:45:31

2K+ Views

This example demonstrates how to handle the click event in Listview in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.ArrayAdapter import android.widget.ListView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import kotlin.collections.ArrayList class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"     ... Read More

How to check whether a headset is plugged into an Android device using Kotlin?

Azhar
Updated on 18-Aug-2020 11:44:32

397 Views

This example demonstrates how to check whether a headset is plugged into an Android device using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to src/MainActivity.ktimport android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.IntentFilter import android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    var broadcastReceiver: BroadcastReceiver? = null    var microphonePluggedIn = false    override fun onCreate(savedInstanceState: Bundle?) {   ... Read More

How to programmatically set drawableLeft on the Android button using Kotlin?

Azhar
Updated on 18-Aug-2020 11:36:17

1K+ Views

This example demonstrates how to programmatically set drawableLeft on the Android button using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.graphics.drawable.Drawable import android.os.Bundle import android.widget.Button import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val button: ... Read More

How do I get the height and width of the Android Navigation Bar programmatically using Kotlin?

Azhar
Updated on 18-Aug-2020 11:32:20

733 Views

This example demonstrates how to get the height and width of the Android Navigation Bar programmatically using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.content.res.Resources import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"   ... Read More

How to set only numeric values for edittext in Android using Kotlin?

Azhar
Updated on 18-Aug-2020 11:30:08

2K+ Views

This example demonstrates how to set only numeric values for edittext in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.text.InputType import android.widget.Button import android.widget.EditText import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"     ... Read More

How to create a Dialog Box without a title in Android using Kotlin?

Azhar
Updated on 18-Aug-2020 11:27:56

325 Views

This example demonstrates how to create a Dialog Box without a title in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml         Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Toast import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val builder ... Read More

How to change the Text color of Menu item in Android using Kotlin?

Azhar
Updated on 18-Aug-2020 11:24:37

1K+ Views

This example demonstrates how to change the Text color of Menu item in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.         Step 3 − Add the following code to res/menu/menu_items.xml             Step 4 − Add the following code to res/values/styles.xml                     @color/colorPrimary       @color/colorPrimaryDark       @color/colorAccent   ... Read More

How to make a specific text on TextView bold in Android using Kotlin?

Azhar
Updated on 18-Aug-2020 11:20:39

2K+ Views

This example demonstrates how to make a specific text on TextView bold in Android using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml         Step 3 − Add the following code to src/MainActivity.ktimport android.graphics.Typeface import android.os.Bundle import android.text.SpannableString import android.text.Spanned import android.text.style.StyleSpan import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = ... Read More

How to validate Email Address in Android on EditText using Kotlin?

Azhar
Updated on 18-Aug-2020 11:18:26

840 Views

This example demonstrates how to validate Email Address in Android on EditText using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new projectStep 2 − Add the following code to res/layout/activity_main.xml.             Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.Button import android.widget.EditText import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var emailId: EditText    var emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\.+[a-z]+"    override fun onCreate(savedInstanceState: Bundle?) {     ... Read More

How to play YouTube videos in my Android application using Kotlin?

Azhar
Updated on 18-Aug-2020 11:16:40

785 Views

This example demonstrates how to play YouTube videos in my Android application using Kotlin.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     Step 3 − Add the following code to src/MainActivity.ktimport androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import java.util.* class MainActivity : AppCompatActivity() {    private lateinit var recyclerView:RecyclerView    private var youtubeVideos = Vector()    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)     ... Read More

Advertisements