Found 2041 Articles for Mobile Development

How to convert pixels to dp in an Android App using Kotlin?

Azhar
Updated on 05-Nov-2020 14:40:46

632 Views

This example demonstrates how to convert pixels to dp 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.content.Context import android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import kotlin.math.roundToInt class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp" ... Read More

How to show current location on a Google Map on Android using Kotlin?

Azhar
Updated on 05-Nov-2020 14:40:08

4K+ Views

This example demonstrates how to show current location on a Google Map on 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 given dependency in the build.gradle (Module: app)implementation 'com.google.android.gms:play-services-maps:17.0.0' implementation 'com.google.android.gms:play-services-location:17.0.0' implementation 'com.google.android.gms:play-services-maps:17.0.0'Step 4 − Add the following code to src/MainActivity.ktimport android.Manifest import android.content.pm.PackageManager import android.location.Location import android.os.Bundle import android.widget.Toast import androidx.core.app.ActivityCompat import androidx.fragment.app.FragmentActivity import com.google.android.gms.location.FusedLocationProviderClient import com.google.android.gms.location.LocationServices import com.google.android.gms.maps.CameraUpdateFactory import com.google.android.gms.maps.GoogleMap import com.google.android.gms.maps.OnMapReadyCallback import com.google.android.gms.maps.SupportMapFragment import com.google.android.gms.maps.model.LatLng ... Read More

How to get the IP address of the Android device programmatically using Kotlin?

Azhar
Updated on 05-Nov-2020 14:37:08

3K+ Views

This example demonstrates how to get the IP address of the Android device 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.Context import android.net.wifi.WifiManager import android.os.Bundle import android.text.format.Formatter 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 retrieve Android API version programmatically using Kotlin?

Azhar
Updated on 05-Nov-2020 14:36:13

588 Views

This example demonstrates how to retrieve Android API version 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.Build import android.os.Bundle import android.widget.Button import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var textView: TextView    var androidVersion = 0    override fun onCreate(savedInstanceState: Bundle?) {     ... Read More

How to draw a line in Android using Kotlin?

Azhar
Updated on 05-Nov-2020 14:35:29

1K+ Views

This example demonstrates how to draw a line 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.Bitmap import android.graphics.Canvas import android.graphics.Color import android.graphics.Paint import android.os.Bundle import android.widget.Button import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var imageView: ImageView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)   ... Read More

How to rotate an image in imageview by an angle on Android using Kotlin?

Azhar
Updated on 05-Nov-2020 14:34:35

840 Views

This example demonstrates how to rotate an image in imageview by an angle on 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.ImageView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var imageView: ImageView    lateinit var btnRotate: Button    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main) ... Read More

How to set the color of TextView span in Android using Kotlin?

Azhar
Updated on 05-Nov-2020 13:07:02

709 Views

This example demonstrates how to set the color of TextView span 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.Color import android.os.Bundle import android.text.SpannableString import android.text.Spanned import android.text.style.ForegroundColorSpan 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)     ... Read More

How to parse HTML in Android using Kotlin?

Azhar
Updated on 05-Nov-2020 13:06:23

3K+ Views

This example demonstrates how to parse HTML 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 given dependency in the build.gradle (Module: app)implementation 'org.jsoup:jsoup:1.11.2'Step 4 − 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 org.jsoup.Jsoup import org.jsoup.nodes.Document import org.jsoup.select.Elements import java.io.IOException class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var textView: TextView ... Read More

How to create a Custom Ratingbar in Android using Kotlin?

Azhar
Updated on 05-Nov-2020 13:02:28

812 Views

This example demonstrates how to create a Custom Ratingbar 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.RatingBar import android.widget.RatingBar.OnRatingBarChangeListener import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var ratingBar: RatingBar    lateinit var button: Button    lateinit var textView: TextView    override fun onCreate(savedInstanceState: Bundle?) { ... Read More

How to detect application heap size in Android using Kotlin?

Azhar
Updated on 05-Nov-2020 13:01:40

190 Views

This example demonstrates how to detect application heap size 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.ActivityManager import android.content.Context import android.os.Bundle import android.view.View import android.widget.TextView import androidx.appcompat.app.AppCompatActivity import java.util.* class MainActivity : AppCompatActivity() {    private lateinit var textView: TextView    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main) ... Read More

Advertisements