目的:更改toast消息位置
语言:Kotlin
原代码
trueButton.setOnClickListener { view: View ->
// Do something in response to the click here
Toast.makeText(
this,
R.string.correct_toast,
Toast.LENGTH_SHORT)
.show()
}
falseButton.setOnClickListener { view: View ->
// Do something in response to the click here
Toast.makeText(
this,
R.string.incorrect_toast,
Toast.LENGTH_SHORT)
.show()
}
修改:
①用val定义原本的Toast.makeText为toast
②使用setGravity修改位置为(Gravity.CENTER,0,0)
trueButton.setOnClickListener { view: View ->
// Do something in response to the click here
val toast = Toast.makeTe