Search code examples
androidkotlinfont-sizetoast

How do you increase the Toast font size in Kotlin?


I read this article on changing the Toast message size in Java, but how would this be done in Kotlin?


Solution

  • The equivalent Kotlin code of the answer. Android Studio also transforms Java code into Kotlin automatically. Just copy and paste it.

    Edit for activity :

     val toast = Toast.makeText(this,  "Text" , Toast.LENGTH_SHORT)
    //the default toast view group is a relativelayout
    val toastLayout = toast.getView() as ViewGroup
    val toastTV =  toastLayout.getChildAt(0) as TextView
    toastTV.setTextSize(30)
    toast.show()