adrianfc
5/1/2020 - 9:03 AM

Keyboard Management

// implement OnKeyListener
public class MainActivity extends AppCompatActivity implements View.OnClickListener, View.OnKeyListener {

    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {

        if (keyCode == KeyEvent.KEYCODE_ENTER  && event.getAction() == KeyEvent.ACTION_DOWN ) {

            signUpClicked(v); // 
        }
    
       return false;
    }

// close the keyboard when user clicks away from the EditTexts
if (view.getId() == R.id.logoImageView || view.getId() == R.id.backgroundLayout) {
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
            inputMethodManager.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
        }