crazyfool crazyfool - 1 year ago 71
Android Question

Android - Keyboard not appearing in floating window

I'm writing an application that uses the following code to draw an edittext on the screen over running applications:

WindowManager.LayoutParams params = new WindowManager.LayoutParams(
| WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,

windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

windowManager.addView(mEditText, params);

The xml for the edittext is:

android:focusableInTouchMode="true" />

However focusing on this does not bring up the keyboard. I've also tried programmatically bringing it up with an onFocusListener:

mEditText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
if(hasFocus) {
Log.d("", "Has focus");
((InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
} else {
Log.d("", "Lost focus");

But although that is called, as seen from the logcat, nothing happens. The only method I've found so far to display the keyboard is using:

getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(0, 0);

But that seems to type onto the screen and not into the edittext.
I've also tried clear focusable when the edittext is displayed but to no avail.

I'm guessing the issue is because I'm using a "floating window" but there must be a way to make this work as apps such as floating calculators exist on the playstore which take input.. Anyone have any ideas? I'm stumped :(

Answer Source

My bad.. I realized if I remove the WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE it works fine.. silly mistake

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download