Skip to content

Commit

Permalink
fix: hide keyboard when login button pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-conway committed Nov 25, 2021
1 parent 2d54185 commit cbc816b
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package com.example.nimblesurveys.login

import android.animation.AnimatorSet
import android.content.Context
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.navigation.fragment.findNavController
Expand Down Expand Up @@ -50,6 +52,7 @@ class LoginFragment : Fragment() {

private fun initUi() {
binding.bLogin.setOnClickListener {
hideKeyboard(it)
val email = binding.etUsername.text.toString()
val password = binding.etPassword.text.toString()
viewModel.login(email, password)
Expand Down Expand Up @@ -89,4 +92,9 @@ class LoginFragment : Fragment() {
}
}
}

private fun hideKeyboard(view: View) {
val inputMethodManager = view.context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
inputMethodManager.hideSoftInputFromWindow(view.windowToken, 0)
}
}

0 comments on commit cbc816b

Please sign in to comment.