Hide Soft Keyboard on Android After Clicking Outside EditText Using Kotlin

Azhar
Updated on 26-May-2020 07:41:36

2K+ Views

This example demonstrates how to hide a soft keyboard on android after clicking outside EditText 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.view.View import android.view.inputmethod.InputMethodManager import android.widget.EditText import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var editText: EditText    lateinit var textView: TextView    override fun onCreate(savedInstanceState: Bundle?) { ... Read More

Display Count of Notifications in Android App Launcher Using Kotlin

Azhar
Updated on 26-May-2020 07:37:07

557 Views

This example demonstrates how to display count of notifications in the Android App launcher 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.NotificationChannel import android.app.NotificationManager import android.app.PendingIntent import android.content.Context import android.content.Intent import android.os.Build import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity import androidx.core.app.NotificationCompat class MainActivity : AppCompatActivity() {    var count = 0    private val channelId = "10001"    private ... Read More

Call Activity Method from Fragment in Android App using Kotlin

Azhar
Updated on 26-May-2020 07:32:36

5K+ Views

This example demonstrates how to call an activity method from a fragment 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.os.Bundle import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val fragmentManager ... Read More

Change Spinner Text Size and Color in Android App Using Kotlin

Azhar
Updated on 26-May-2020 07:26:36

7K+ Views

This example demonstrates how to change spinner text size and text color 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.widget.ArrayAdapter import android.widget.Spinner import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var spinner: Spinner       override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = ... Read More

Determine Size of Android View at Runtime Using Kotlin

Azhar
Updated on 26-May-2020 07:23:05

435 Views

This example demonstrates how to determine the size of an Android view at runtime 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 − Copy and paste an image (.png/.jpg/.jpeg) into res/drawableStep 4 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.view.View import android.view.ViewTreeObserver.OnGlobalLayoutListener import android.widget.ImageView import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    private lateinit var imageView: ImageView    override fun onCreate(savedInstanceState: Bundle?) { ... Read More

Disable Copy Paste in EditText using Kotlin

Azhar
Updated on 26-May-2020 07:19:26

2K+ Views

This example demonstrates how to disable copy/paste from/to EditText in the 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.view.ActionMode import android.view.Menu import android.view.MenuItem import android.widget.EditText import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var editText: EditText    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title ... Read More

Add Calendar Events in Android App Using Kotlin

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

3K+ Views

This example demonstrates how to add calendar events 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.content.Intent import 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"    }    fun addCalendarEvent(view: ... Read More

Read a Simple Text File in an Android App using Kotlin

Azhar
Updated on 26-May-2020 07:05:25

1K+ Views

This example demonstrates how to read a simple text file 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 − Create a new Android Resource directory (raw.xml) and add a text file in the res/rawStep 4 − Add the following code to src/MainActivity.ktimport android.os.Bundle import android.view.View import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import java.io.BufferedReader import java.io.IOException import java.io.InputStream import java.io.InputStreamReader class MainActivity ... Read More

Animate Background Color Change of a View in Android Using Kotlin

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

633 Views

This example demonstrates how to animate the change of background color of a view 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.graphics.Color import android.graphics.drawable.ColorDrawable import android.graphics.drawable.TransitionDrawable import android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var textView: TextView    lateinit var button: Button    override fun onCreate(savedInstanceState: Bundle?) { ... Read More

Delete SharedPreferences Data for Android App Using Kotlin

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

1K+ Views

This example demonstrates how to delete SharedPreferences data for my 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.content.SharedPreferences import android.os.Bundle import android.widget.Button import android.widget.TextView import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var textView: TextView    lateinit var tvAfterDelete: TextView    lateinit var sharedPreferences: SharedPreferences    lateinit var editor: ... Read More

Advertisements