0

I am developing an android keyboard with a search box inside it. I can detect when the user press my search box and then commit the text he types to my search box.

The problem is that I can't manage to detect when the user is pressing the original EditText (the one that opened the keyboard) because it's not my view.

This is how basically the keyboard looks like:

keyboard

The keyboard is surrounded by the blue square, and my edit text is surrounded by the red square.

I tried setting this listener on my editText but with no luck: (source)

editText.setOnFocusChangeListener(new OnFocusChangeListener() {
    @Override
    public void onFocusChange(View view, boolean hasFocus) {
        if (hasFocus) {
            Toast.makeText(getApplicationContext(), "Got the focus", Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(getApplicationContext(), "Lost the focus", Toast.LENGTH_LONG).show();
        }
    }
});

The listener isn't being called when I press on the other editText. Probably because it is not a part of my service.

Even if I could some how detect a click on screen that is outside of my service layout, it would be great.

Thanks for any help!

Amit Klein
  • 104
  • 1
  • 7

1 Answers1

0

Although your question is very basic I think I can help here try this below snip of code and let me know if it works for you.

public void showKeyboard(View view) {
    InputMethodManager myKeyboard = (InputMethodManager) getSystemService(Context
            .INPUT_METHOD_SERVICE);
    myKeyboard.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);

}

public void hideKeyboard() {
    InputMethodManager myKeyboard = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
    myKeyboard.hideSoftInputFromWindow(EditText1.getWindowToken(), 0);
}

Also this is a duplicate question, see here: Android: show soft keyboard automatically when focus is on an EditText

Please try the ol' Google before posting questions here, it can stall your progress greatly while you wait for others to comment on your post when the answer is out there :) Also as a side note if you post duplicate questions and do not get enough up votes on your post, Stack Overflow can ban you from posting.

Also you can review the Android Developer Docs on this topic as well: https://developer.android.com/training/keyboard-input/visibility

  • Hey thanks for the fast reply! Unfortunately this is not my case. The keyboard is already shown. The problem is that I can't detect that the user pressed an editbox that is not my app's. I remind that I am developing the keyboard, not the app. Thanks! – Amit Klein Sep 19 '20 at 09:32
  • Also I wish I found another similar question but I haven't :( there aren't many questions about developing keyboarda (ime) – Amit Klein Sep 19 '20 at 09:37
  • Can you provide more detail on what you are requesting, try pasting the code you already have in your original post. I'll see if I can help you accomplish what your trying to do. – AndroidDude91 Sep 20 '20 at 02:07
  • Hey! I am really sorry for the late replay! I haven't saw you commented, and in the meanwhile I worked on other parts of the keyboard.. I Edited my question :) – Amit Klein Oct 06 '20 at 10:47