Change Text Color of Menu Item in Android Using Kotlin

Azhar
Updated on 18-Aug-2020 11:24:37

2K+ Views

This example demonstrates how to change the Text color of Menu item 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 res/menu/menu_items.xml             Step 4 − Add the following code to res/values/styles.xml                     @color/colorPrimary       @color/colorPrimaryDark       @color/colorAccent   ... Read More

Make Specific Text Bold in TextView using Kotlin

Azhar
Updated on 18-Aug-2020 11:20:39

3K+ Views

This example demonstrates how to make a specific text on TextView bold 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.Typeface import android.os.Bundle import android.text.SpannableString import android.text.Spanned import android.text.style.StyleSpan 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 = ... Read More

Validate Email Address in Android EditText using Kotlin

Azhar
Updated on 18-Aug-2020 11:18:26

1K+ Views

This example demonstrates how to validate Email Address in Android on 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 projectStep 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.EditText import android.widget.Toast import androidx.appcompat.app.AppCompatActivity class MainActivity : AppCompatActivity() {    lateinit var button: Button    lateinit var emailId: EditText    var emailPattern = "[a-zA-Z0-9._-]+@[a-z]+\.+[a-z]+"    override fun onCreate(savedInstanceState: Bundle?) {     ... Read More

Play YouTube Videos in Android Application Using Kotlin

Azhar
Updated on 18-Aug-2020 11:16:40

975 Views

This example demonstrates how to play YouTube videos in my Android application 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 androidx.appcompat.app.AppCompatActivity import android.os.Bundle import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import java.util.* class MainActivity : AppCompatActivity() {    private lateinit var recyclerView:RecyclerView    private var youtubeVideos = Vector()    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)     ... Read More

Detect Swipe Direction in Android Using Kotlin

Azhar
Updated on 18-Aug-2020 11:11:34

829 Views

This example demonstrates how to detect swipe direction between left/right and up/down 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.content.Context import android.os.Bundle import android.view.GestureDetector import android.view.MotionEvent import android.view.View import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import kotlin.math.abs class MainActivity : AppCompatActivity() {    var onSwipeTouchListener: OnSwipeTouchListener? = null    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)   ... Read More

Take a Screenshot Programmatically in Android Using Kotlin

Azhar
Updated on 18-Aug-2020 11:06:34

3K+ Views

This example demonstrates how to take a screenshot 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.         Step 3 − Add the following code to src/MainActivity.ktimport android.graphics.Bitmap import android.graphics.Color import android.os.Bundle import android.view.View import android.widget.Button import android.widget.ImageView import androidx.appcompat.app.AppCompatActivity @Suppress("DEPRECATION") class MainActivity : AppCompatActivity() {    private lateinit var main: View    private lateinit var imageView: ImageView    override fun onCreate(savedInstanceState: Bundle?) {       ... Read More

Display Progress Dialog Before Starting Activity in Android using Kotlin

Azhar
Updated on 18-Aug-2020 11:04:05

381 Views

This example demonstrates how to display progress dialog before starting an activity 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.ProgressDialog import android.os.AsyncTask import android.os.Bundle import androidx.appcompat.app.AppCompatActivity @Suppress("DEPRECATION") class MainActivity : AppCompatActivity() {    private lateinit var progressDialog: ProgressDialog    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title ... Read More

Permanently Hide Navigation Bar in Android Activity Using Kotlin

Azhar
Updated on 18-Aug-2020 11:01:29

1K+ Views

This example demonstrates how to permanently hide the Navigation Bar in an 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.os.Build import android.os.Bundle import android.view.View import androidx.appcompat.app.AppCompatActivity @Suppress("DEPRECATED_IDENTITY_EQUALS", "DEPRECATION") class MainActivity : AppCompatActivity() {    private var currentApiVersion: Int = 0    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)     ... Read More

Convert Milliseconds to Date Format in Android Using Kotlin

Azhar
Updated on 18-Aug-2020 10:55:44

6K+ Views

This example demonstrates how to convert milliseconds to date format 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.TextView import androidx.appcompat.app.AppCompatActivity import java.text.SimpleDateFormat class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       setContentView(R.layout.activity_main)       title = "KotlinApp"       val textView: TextView = ... Read More

Hide Status Bar in Android Using Kotlin

Azhar
Updated on 18-Aug-2020 09:30:12

1K+ Views

This example demonstrates how to hide status bar 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 androidx.appcompat.app.AppCompatActivity import android.os.Bundle import android.view.Window import android.view.WindowManager class MainActivity : AppCompatActivity() {    override fun onCreate(savedInstanceState: Bundle?) {       super.onCreate(savedInstanceState)       requestWindowFeature(Window.FEATURE_NO_TITLE)       window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,       WindowManager.LayoutParams.FLAG_FULLSCREEN)       setContentView(R.layout.activity_main)       title = ... Read More

Advertisements