默认Toast是显示在底部的,可以通过以下方法让其显示在顶部正中
val makeText = Toast.makeText(
this,
R.string.correct_toast,
Toast.LENGTH_SHORT
)
makeText.setGravity(Gravity.TOP,0,0)
makeText.show()
通过以下方法让其显示在右上角:
private fun getScreenWidth(): Int {
val outMetrics = DisplayMetrics()
windowManager.defaultDisplay.getMetrics(outMetrics)
Log.i("width",outMetrics.toString())
return outMetrics.widthPixels
}
makeText.setGravity(Gravity.TOP,getScreenWidth()/2,0)