Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Make the parent view(content view of your activity) clickable and focusable by adding the following attributes
- android:clickable="true"
- android:focusableInTouchMode="true"
- */
- class MyClass {
- private var editText: View
- init {
- editText = findViewById(R.id.editText)
- }
- editText.onFocusChangeListener = View.OnFocusChangeListener
- {
- v, hasFocus ->
- if (!hasFocus) {
- hideKeyboard(v)
- }
- }
- // Функцию hideKeyboard() можно вынести в Util класс
- private fun hideKeyboard(view: View) {
- val inputMethodManager = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
- inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement