尝试这个:
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
lateinit var dialogBuilder: AlertDialog.Builder
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
dialogBuilder = AlertDialog.Builder(this)
dialogBuilder.setMessage("Check your internet connection")
.setPositiveButton("OK") { _, _ ->
Toast.makeText(this,"Ok",Toast.LENGTH_LONG).show()
}.setCancelable(false)
.create().show()
}
}
在颜色方面,我们有:
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#00ff00</color>
</resources>