Posts

Showing posts from April, 2023

Generate Random Color - Android Studio - Java

Image
Generate random color(s) using Android Studio and Java There may be some situations in which you need the feature to generate a random color.  For example, in a list of items, if you want to assign different colors to each item/row, you may have seen the WhatsApp Group Chat List, where each person's name is displayed in a different color.  I'll do it using a button click. You can do it according to your requirements/needs. >> View for Java >> View for Kotlin >> View for Compose 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= ...

Generate Random Color - Android Studio - Kotlin

Image
Generate random color(s) using Android Studio and Kotlin There may be some situations in which you need the feature to generate a random color.  For example, in a list of items, if you want to assign different colors to each item/row, you may have seen the WhatsApp Group Chat List, where each person's name is displayed in a different color.  I'll do it using a button click. You can do it according to your requirements/needs. >> View for Java >> View for Kotlin >> View for Compose 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" ...