Posts

Showing posts from April, 2023

Generate Random Color | Android Studio | Kotlin

Image
Generate random color(s) in Android Studio IDE with Kotlin language There may have some situations in which you need the feature to generate the random color.  For example, in a list of items if you want to give different colors to each item/row or you may have seen the WhatsApp Group Chat List, each person's name is of a different color.  I'll do it using a button click. You can do it according to your requirements/needs. >>View For Java Video Coming Soon Code Code Snippet val rnd = Random() val color = Color.argb( 255 , rnd.nextInt( 256 ), rnd.nextInt( 256 ), rnd.nextInt( 256 )) activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:app= "http://schemas.android.com/apk/res-auto" xmlns:tools= "http://schemas.android.com/tools" android:layout_width= "match_parent" android:layout_height= "matc

Generate Random Color | Android Studio | Java

Image
Generate random color(s) in Android Studio IDE with Java language There may have some situations in which you need the feature to generate the random color.  For example, in a list of items if you want to give different colors to each item/row or you may have seen the WhatsApp Group Chat List, each person's name is of a different color.  I'll do it using a button click. You can do it according to your requirements/needs. >>View For Kotlin Video Coming Soon Code Code Snippet Random rnd = new Random (); int color = Color . argb ( 255 , rnd . nextInt ( 256 ), rnd . nextInt ( 256 ), rnd . nextInt ( 256 )); activity_main.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:app= "http://schemas.android.com/apk/res-auto" xmlns:tools= "http://schemas.android.com/tools" android:layout_width= "match_parent" andr