Found 417 Articles for Kotlin

How to switch between different Activities in Android using Kotlin?

Azhar
Updated on 21-Jul-2020 08:25:27

6K+ Views

This example demonstrates how to switch between different Activities 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent 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:Button = findViewById(R.id.btnOpenAct2)       button.setOnClickListener ... Read More

How to create Tab Layout in an Android App using Kotlin?

Azhar
Updated on 21-Jul-2020 08:18:37

3K+ Views

This example demonstrates how to create Tab Layout 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.viewpager.widget.ViewPager import com.google.android.material.tabs.TabLayout import com.google.android.material.tabs.TabLayout.OnTabSelectedListener import com.google.android.material.tabs.TabLayout.TabLayoutOnPageChangeListener class MainActivity : AppCompatActivity() {    lateinit var tabLayout: TabLayout    lateinit var viewPager: ViewPager    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)     ... Read More

How do you format date and time in Android using Kotlin?

Azhar
Updated on 21-Jul-2020 08:10:24

2K+ Views

This example demonstrates how to format date and time 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.text.SimpleDateFormat import java.util.* class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val textView: TextView = findViewById(R.id.textView)   ... Read More

How to get the screen DPI programmatically in Android using Kotlin?

Azhar
Updated on 21-Jul-2020 08:04:31

456 Views

This example demonstrates how to get the screen DPI programmatically 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.app.Activity import android.os.Bundle import android.util.DisplayMetrics import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var textView: TextView    var value = 0f    lateinit var displayMetrics: DisplayMetrics    var activity: Activity? ... Read More

How to detect if a user is using an Android tablet or a phone using Kotlin?

Azhar
Updated on 21-Jul-2020 07:59:31

528 Views

This example demonstrates how to detect if a user is using an Android tablet or a phone 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.content.Context import android.os.Bundle import android.telephony.TelephonyManager import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"   ... Read More

How to change the font face of Webview in Android using Kotlin?

Azhar
Updated on 21-Jul-2020 07:55:30

630 Views

This example demonstrates how to change the font face of Webview 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.Example Step 3 − Create an assets folder. Right click asset folder >> Create a new file (webView.html) and the following code − WebView9 @font-face {    font-family: 'Font';    src:url("file:///android_asset/Font.otf") } body {    font-family: 'Font', serif;    font-size: medium;    text-align: justify;    color:#ffffff } ... Read More

How to change the language of an app when the user selects language using Kotlin?

Azhar
Updated on 21-Jul-2020 07:46:34

2K+ Views

This example demonstrates how to change the language of an app when the user selects language 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.content.Intent import android.os.Bundle import android.view.View import android.widget.AdapterView import android.widget.AdapterView.OnItemSelectedListener import android.widget.ArrayAdapter import android.widget.Spinner import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import java.util.* import kotlin.system.exitProcess @Suppress("DEPRECATION") class MainActivity : AppCompatActivity() {    lateinit var spinner: Spinner    lateinit var locale: ... Read More

How to put a ListView into a ScrollView without it collapsing on Android in Kotlin?

Azhar
Updated on 21-Jul-2020 07:35:06

446 Views

This example demonstrates how to put a ListView into a ScrollView without it collapsing on Android in 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.Example Step 3 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.widget.ArrayAdapter import android.widget.ListView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private val listViewArray = arrayOf(       "ONE", "TWO", "THREE", "FOUR", "FIVE", "SIX", "SEVEN", "EIGHT", "NINE",       "TEN", "Eleven", "Twelve", ... Read More

Why Kotlin will replace Java for Android App Development

AmitDiwan
Updated on 13-Jul-2020 11:54:59

149 Views

While working with Kotlin, Java libraries and frameworks can be used. This can be done with the help of advanced frameworks, without having to change the whole project. Java and Kotlin co-exist and can be present in the same project.Kotlin code can be placed inside Android Studio, without making the whole project in Kotlin.It is an open source platform that also helps in quick development of projects. It is easy, and readable, and considerably requires lesser coding in comparison to Java.Kotlin was developed by JetBrains, and IntelliJ is the IDE which Android Studio also uses.Kotlin plugin can be installed and ... Read More

How to create EditText accepts Alphabets only in Kotlin?

Azhar
Updated on 05-Nov-2020 15:18:29

129 Views

This example demonstrates how to create EditText accepts Alphabets only in 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.kt        

Advertisements