Azhar

Azhar

451 Articles Published

Articles by Azhar

Page 2 of 46

How to communicate between Activity and Service in Android using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 1K+ Views

This example demonstrates how to communicate between Activity and Service 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.app.Service import android.content.Intent import android.media.MediaPlayer import android.os.Bundle import android.os.IBinder import android.view.View import android.widget.Button import android.widget.Toast import androidx.annotation.Nullable import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity(), View.OnClickListener {    private lateinit var buttonStart: Button    private lateinit var buttonStop: Button ...

Read More

How to execute an Async task repeatedly after fixed time intervals in Android using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 366 Views

This example demonstrates how to execute an Async task repeatedly after fixed time intervals 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 androidx.appcompat.app.AppCompatActivity import android.os.AsyncTask import android.os.Bundle import android.os.Handler import android.widget.Toast @Suppress("DEPRECATION") class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp" ...

Read More

How to detect user inactivity for 5 seconds in Android using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 910 Views

This example demonstrates how to detect user inactivity for 5 seconds 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.os.Handler import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var handler: Handler    lateinit var runnable: Runnable    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)     ...

Read More

How to use a custom font in an Android project using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 810 Views

This example demonstrates how to use a custom font in an Android project 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.xm         Step 3 − Create an asset folder and add the fonts in the font folder.Step 4 − Add the following code to src/MainActivity.ktimport android.graphics.Typeface import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)     ...

Read More

How to use AutoCompleteTextView in an Android App using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 2K+ Views

This example demonstrates how to use AutoCompleteTextView in an Android App 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.AutoCompleteTextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private val fruits = arrayOf("Apple", "Banana", "Cherry", "Date", "Grape", "Kiwi", "Mango", "Pear")    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)   ...

Read More

How to pickup & hangup calls in Android using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 411 Views

This example demonstrates how to pickup & hangup calls in Android using KotlinStep 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.Manifest import android.content.BroadcastReceiver import android.content.Context import android.content.Intent import android.content.pm.PackageManager import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Toast import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)     ...

Read More

How to set margins in an Android LinearLayout programmatically using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 3K+ Views

This example demonstrates how to set margins in an Android LinearLayout 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.os.Bundle import android.view.Gravity import android.widget.Button import android.widget.RelativeLayout import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val relativeLayout: RelativeLayout = ...

Read More

How to detect click on HTML button through javascript in Android WebView using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 1K+ Views

This example demonstrates how to detect click on HTML buttons through javascript in Android WebView using Kotlin.This example demonstrates how to detect click on HTML buttons through javascript in Android WebView 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 − Create an asset folder and create a file.htm and add the following code − First name: Last name:    function getValues() { ...

Read More

How to make a phone call using intent in Android using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 4K+ Views

This example demonstrates how to make a phone call using intent in Android using KotlinStep 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.Intent import android.net.Uri import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"    }    fun ...

Read More

How to change a TextView's style at runtime in Android using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 3K+ Views

This example demonstrates how to change a TextView's style at runtime 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 in res/values/styles.xml           bold|italic       #FFFFFF               normal       #C0C0C0     Step 4 − Add the following code in res/values/colors.xml    @android:color/holo_green_light    @android:color/holo_red_dark Step ...

Read More
Showing 11–20 of 451 articles
« Prev 1 2 3 4 5 46 Next »
Advertisements