Android 如何增加Kotlin中的Toast字体大小?

Android 如何增加Kotlin中的Toast字体大小?,android,kotlin,font-size,toast,Android,Kotlin,Font Size,Toast,我读过关于在Java中更改Toast消息大小的文章,但是在Kotlin中如何做到这一点呢?答案的等效Kotlin代码。Android Studio还自动将Java代码转换为Kotlin。只需复制并粘贴它 为活动编辑: val toast = Toast.makeText(this, "Text" , Toast.LENGTH_SHORT) //the default toast view group is a relativelayout val toastLayout

我读过关于在Java中更改Toast消息大小的文章,但是在Kotlin中如何做到这一点呢?

答案的等效Kotlin代码。Android Studio还自动将Java代码转换为Kotlin。只需复制并粘贴它

为活动编辑:

 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()

这导致应用程序关闭,并表示,
java.lang.NullPointerException:null不能强制转换为非null类型的android.widget.RelativeLayout
,它指的是带有
binding.fightButton.setOnClickListener{battle()}
val playerHitLayout=playerHitMonster.view as RelativeLayout的行。不确定发生了什么。我不知道您的上下文是活动还是片段,我只是更改了codeActivity,而不是片段。错误显示“playerHitMonster.view”为空。请检查您是否以正确的方式声明了它。现在我得到的
android.widget.Toast不能转换为android.widget.RelativeLayout
。我为什么要为相对布局干杯?因为这似乎不起作用。这是如何增加面包片的大小: