Reputation: 44973
I'm wondering how I can create a custom pop-up like the one in the screenshot below (borrowed from the Swype keyboard), where I can have a couple of buttons, which each commit a string to the currently "connected" TextView
(via a InputConnection).
Please note: this is an InputMethodService and not an ordinary Activity
. I already tried launching a separate Activity
with Theme:Dialog
. However, as soon as that one opens I lose my focus with the TextView
and my keyboard disappears (and with that my InputConnection
is gone).
Upvotes: 5
Views: 4339
Reputation: 17834
Peace be upon those who follow the guidance,
solution :
AlertDialog dialog;
//add this to your code
dialog = builder.create();
Window window = dialog.getWindow();
WindowManager.LayoutParams lp = window.getAttributes();
lp.token = mInputView.getWindowToken();
lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
window.setAttributes(lp);
window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
//end addons
dialog.show();
===== UPDATE 30.09.2015 mInputView its the general name of your keyboard class ..see
@Override
public View onCreateInputView() {
mInputView =(MyKeyboardView) getLayoutInflater().inflate( R.layout.input, null);
....
}
More info : http://developer.android.com/guide/topics/text/creating-input-method.html
good luck.
Upvotes: 1
Reputation: 1528
Correct answer:
This will show your popup above the IME as in your screenshot.
Upvotes: 1
Reputation: 12666
I was banging my head against this problem too and I finally figured it out. The above solutions are correct although as you pointed out they cannot be used from an InputMethodService because it is not an Activity. The trick is to create the PopupWindow in a subclass of KeyboardView. By using a negative Y position, the PopupWindow can appear above the keyboard like Swype.
Good luck, Barry
Upvotes: 1
Reputation: 41972
You can try using a PopupWindow
. You'll have to do a bit of hacking to get it to do what you want and the only good documentation for it is the source.
Upvotes: 2