Draw Text on Image in Android Using Kotlin

Azhar
Updated on 21-Jul-2020 12:52:27

1K+ Views

This example demonstrates how to draw text On image 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.graphics.Color import android.os.Bundle 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"       val textView: TextView = findViewById(R.id.text)       ... Read More

Get and Store Device ID in Android Using Kotlin

Azhar
Updated on 21-Jul-2020 12:47:00

5K+ Views

This example demonstrates how to get and store device ID 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.provider.Settings 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"       val textView: TextView = findViewById(R.id.textView)     ... Read More

Update ListView After Inserting Values in Android SQLite Using Kotlin

Azhar
Updated on 21-Jul-2020 12:44:14

692 Views

This example demonstrates how to update listview after insert values in Android sqlite 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.* import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private lateinit var save: Button    private lateinit var refresh: Button    private lateinit var name: EditText    private lateinit var salary: EditText   ... Read More

Prevent Dialog from Closing When Button is Clicked in Kotlin

Azhar
Updated on 21-Jul-2020 12:37:51

406 Views

This example demonstrates how to prevent a dialog from closing when a button is clicked 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 androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.widget.Button import android.widget.Toast import androidx.appcompat.app.AlertDialog class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val dialog: ... Read More

Create Focusable EditText Inside ListView on Android Using Kotlin

Azhar
Updated on 21-Jul-2020 12:34:12

545 Views

This example demonstrates how to create Focusable EditText inside ListView 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.Example Step 3 − Add the following code to src/MainActivity.ktimport androidx.appcompat.app.AppCompatActivity import android.annotation.SuppressLint import android.app.LauncherActivity import android.content.Context import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.BaseAdapter import android.widget.EditText import android.widget.ListView import java.util.ArrayList class MainActivity : AppCompatActivity() {    private lateinit var listView: ListView    private lateinit var myAdapter: MyAdapter    override ... Read More

Create Clickable Links in TextView on Android Using Kotlin

Azhar
Updated on 21-Jul-2020 12:26:25

765 Views

This example demonstrates how to create clickable links in a TextView 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.Example Step 3 − Open res/values/strings.xml and add the following code    Your app Name    Tap here to open Google Step 4 − Add the following code to src/MainActivity.ktimport androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.text.method.LinkMovementMethod import android.widget.TextView class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       ... Read More

Turn On Flashlight Programmatically in Android Using Kotlin

Azhar
Updated on 21-Jul-2020 12:13:13

2K+ Views

This example demonstrates how to turn on flashlight 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.xmlExample Step 3 − Add the following code to src/MainActivity.ktimport android.content.Context import android.content.DialogInterface import android.content.pm.PackageManager import android.hardware.camera2.CameraAccessException import android.hardware.camera2.CameraManager import android.os.Build import android.os.Bundle import android.widget.ToggleButton import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private lateinit var cameraManager: CameraManager    private lateinit var cameraId: String    private lateinit var toggleButton: ToggleButton   ... Read More

Build Array to Find Maximum with Exactly K Comparisons in C++

Arnab Chakraborty
Updated on 21-Jul-2020 09:24:12

192 Views

Suppose we have three integers n, m, and k. If we have following algorithm to find the maximum element of an array of positive integers −max_val := -1 max_ind := -1 search_cost := 0 n := size of arr for initialize i := 0, when i < n, update (increase i by 1), do:    if max_val < arr[i], then:       max_val := arr[i]       max_ind := i       (increase search_cost by 1) return max_indWe have to make the array arr which has the following criteria: arr has exactly n integers. all elements arr[i] are in range 1 to m(including) (0

Click Camera Programmatically in Android

Azhar
Updated on 21-Jul-2020 09:23:24

293 Views

This example demonstrates how toStep 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.Manifest import android.content.ContentValues import android.content.Intent import android.content.pm.PackageManager import android.net.Uri import android.os.Bundle import android.provider.MediaStore import android.widget.Button import android.widget.ImageView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.core.app.ActivityCompat import androidx.core.content.ContextCompat class MainActivity : AppCompatActivity() {    lateinit var button: Button    private lateinit var imageView: ImageView    lateinit var imageUri: Uri    private val permissionCode ... Read More

Number of Ways to Paint n x 3 Grid in C++ Program

Arnab Chakraborty
Updated on 21-Jul-2020 09:15:13

179 Views

Suppose we have a grid whose size is n x 3 and we want to paint every cell of the grid with exactly one of the three colors. Here the colors that will be used are Red, Yellow and Green.Now there is a constraint, that is no two adjacent cells have the same color. We have n number of rows of the grid. Finally, we have to find the number of ways we can paint this grid. The answer may be very large so return it modulo 10^9 + 7.So, if the input is like 1, then the output will ... Read More

Advertisements