#Enable Disable Button With Checkbox
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
//get checkbox by id && button
val ckb_terms = findViewById<CheckBox>(R.id.checkbox_terms)
val btnStarted = findViewById<Button>(R.id.btn_getstarted)
//disabling button by default
btnStarted.isEnabled = false
//checking if checkbox is checked to move to the next activity
ckb_terms.setOnCheckedChangeListener { buttonView, isChecked ->
btnStarted.isEnabled = buttonView.isChecked
}
//moving to the next activity
btnStarted.setOnClickListener {
val intent = Intent(this, HomeActivity::class.java)
startActivity(intent)
}
}
}
#Here layout are xml file
android:id="@+id/btn_getstarted"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Started"/>
<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/checkbox_terms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="agree to terms and conditions" />