Found 417 Articles for Kotlin

How to get free size of internal/external memory in Android App using Kotlin?

Azhar
Updated on 26-May-2020 06:31:24

232 Views

This example demonstrates how to get free size of internal/external memory in 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.os.Environment import android.os.StatFs import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var textView: TextView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = ... Read More

How to set the ringtone in Android from Android activity using Kotlin?

Azhar
Updated on 26-May-2020 06:27:26

682 Views

This example demonstrates how to set the ringtone in Android from Android activity 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.Intent import android.media.RingtoneManager import android.net.Uri import android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var btn: Button    lateinit var txtView: TextView    override fun onCreate(savedInstanceState: Bundle?) {       ... Read More

How to set Android Toast duration longer than Toast.LENGTH_LONG using Kotlin?

Azhar
Updated on 26-May-2020 06:20:20

268 Views

This example demonstrates how to set Android Toast duration longer than Toast.LENGTH_LONG 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.CountDownTimer import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private lateinit var mToastToShow: Toast    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp" ... Read More

How to convert a Base64 string into a BitMap image in Android App using Kotlin?

Azhar
Updated on 26-May-2020 06:15:06

1K+ Views

This example demonstrates how to convert a Base64 string into a BitMap image in 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.graphics.Bitmap import android.graphics.BitmapFactory import android.os.Bundle import android.util.Base64 import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity import java.io.ByteArrayOutputStream class MainActivity : AppCompatActivity() {    lateinit var imageView: ImageView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       ... Read More

How to get the width and height of an android.widget.ImageView in Kotlin?

Azhar
Updated on 26-May-2020 06:10:05

559 Views

This example demonstrates how to get the width and height of an android.widget.ImageView 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.ktimport android.os.Bundle import android.widget.Button import android.widget.ImageView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var imageView: ImageView    lateinit var textView: TextView    lateinit var button: Button    override fun onCreate(savedInstanceState: Bundle?) {   ... Read More

How to set the absolute position of a view in Android using Kotlin?

Azhar
Updated on 26-May-2020 06:05:59

483 Views

This example demonstrates how to set the absolute position of a view 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.ImageView 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)       val relativeLayout: RelativeLayout = findViewById(R.id.relativeLayout)       val imageView = ImageView(this)     ... Read More

How to disable Home and other system buttons in Android using Kotlin?

Azhar
Updated on 26-May-2020 06:00:41

446 Views

This example demonstrates how to disable Home and other system buttons 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.ktExampleimport android.os.Bundle import android.view.View 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"    }    override fun onWindowFocusChanged(hasFocus: ... Read More

How to check the amount of RAM to be used by an Android App using Kotlin?

Azhar
Updated on 23-May-2020 14:29:21

426 Views

This example demonstrates how to create a smooth image rotation 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.ktExampleimport android.app.ActivityManager import android.content.Context import android.os.Bundle import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private lateinit var textView: TextView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp" ... Read More

How to create a smooth image rotation in Android using Kotlin?

Azhar
Updated on 23-May-2020 14:25:37

229 Views

This example demonstrates how to create a smooth image rotation 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.ktExampleimport android.os.Bundle import android.view.animation.AnimationUtils import android.widget.Button import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var imageView: ImageView    lateinit var button: Button    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       ... Read More

How to convert a Bitmap to Drawable in Kotlin?

Azhar
Updated on 23-May-2020 14:20:30

1K+ Views

This example demonstrates how to convert a Bitmap to Drawable 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.ktExampleimport android.graphics.Bitmap import android.graphics.drawable.BitmapDrawable import android.graphics.drawable.Drawable import android.os.Bundle import android.widget.Button import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var imageView: ImageView    lateinit var button: Button    lateinit var bitmap: Bitmap    lateinit var drawable: Drawable    override fun onCreate(savedInstanceState: ... Read More

Advertisements