In my app i want to clear focus on back pressed, show something that was hidden, and hide the keyboard.
Problem : when the Keyboard is up, pressing the back button hides it but it doesn't trigger my onBackPressed event ! Meaning i need to go back twice. First back action : keyboard goes down Second back action : my code get's executed
This is the code that I want to execute when the back button is pressed, regardless of the keyboard visibility
override fun onBackPressed() {
val materialEditText2 = findViewById<AppCompatEditText>(R.id.material_edit_text_2)
materialEditText2.visibility = View.VISIBLE
binding.materialEditText.clearFocus()
}
I tried searching online for way too long, best thing I found is this https://code.luasoftware.com/tutorials/android/edittext-clear-focus-on-keyboard-hidden
I don't understand how to implement it