Through a click event, I'm trying to close a Snackbar whenever it is open. However, for some reason, it doesn't get dismissed, despite opening successfully.
- If the
EditTextis empty, I want theSnackbarto appear - else if the
EditTextis not empty, I want theSnackbarto be dismissed
I tried using this, but it didn't work:
if (mSnackbar.isShown) {
mSnackbar.dismiss()
}
Would a callback need to be used in this situation? If yes, I'm not sure where it needs to go.
val mSnackbar = Snackbar.make(mRootView, "Hello World", Snackbar.LENGTH_LONG)
val mEditText = findViewById(R.id.my_edit_text) as EditText
val mBtn = findViewById(R.id.my_btn) as Button
mBtn.setOnClickListener {
if (mTextView.text.isEmpty()) {
mSnackbar.show()
} else {
if (mSnackbar.isShown) {
mSnackbar.dismiss()
}
}
}
Aucun commentaire:
Enregistrer un commentaire