Apps/Applications Articles

Page 28 of 148

How to get the current date and time from the internet in Android using Kotlin?

Azhar
Azhar
Updated on 01-Dec-2020 756 Views

This example demonstrates how to get the current date and time from the internet 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.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.text.SimpleDateFormat import java.util.* class MainActivity : AppCompatActivity() {    lateinit var calendar: Calendar    lateinit var simpleDateFormat: SimpleDateFormat    lateinit var date: String    lateinit ...

Read More

How to write files to the assets folder in android using Kotlin?

Azhar
Azhar
Updated on 01-Dec-2020 1K+ Views

This example demonstrates how to write files to the assets folder 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.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.io.IOException import java.io.InputStream class MainActivity : AppCompatActivity() {    lateinit var textView: TextView    lateinit var button: Button    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState) ...

Read More

Where and how to use static variables in Android using Kotlin?

Azhar
Azhar
Updated on 30-Nov-2020 586 Views

This example demonstrates how to use static variables 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.util.Log import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private val tag = "I'm a Static Variable"    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp" ...

Read More

How do I specify different layouts for portrait and landscape orientations in Android?

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

This example demonstrates how do I specify different layouts for portrait and landscape orientations in androidStep 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 a layout file by right-clicking on the resources, name the file, from the ‘Available qualifiers, select Orientation.Click >> option.Select Landscape from UI mode.Add the following code in the res/layout/land/activity_main.xml         Step 4 − Add the following code to ...

Read More

How to set maximum date in datepicker dialog in Android using Kotlin?

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

This example demonstrates how to set maximum date in datepicker dialog 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.DatePickerDialog import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.text.SimpleDateFormat import java.util.* class MainActivity : AppCompatActivity() {    private var year = 0    private var month = 0    private var day = 0    lateinit var textView: ...

Read More

How to change Screen Orientation programmatically using a Button in Android Kotlin?

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

This example demonstrates how to change Screen Orientation programmatically using a Button in Android 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.pm.ActivityInfo import androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.Toast class MainActivity : AppCompatActivity() {    lateinit var buttonLandscape: Button    lateinit var buttonPortrait: Button    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)     ...

Read More

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 347 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 876 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 781 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
Showing 271–280 of 1,475 articles
« Prev 1 26 27 28 29 30 148 Next »
Advertisements