Chat head kind of pop up with edit text. But key p

2019-03-06 02:15发布

问题:

I have implemented chat head kind of pop up for my application using service. And I have used edit text inside that.

But problem is that when I click on edit text only cursor is visible and keyboard is not coming up. And not even able to select or copy paste the text inside that edit text. Any help? Thanks

回答1:

I found solution to my problem.

I was using the following code earlier:-

Global variables:-

private WindowManager mWindowManager;
WindowManager.LayoutParams params;

Then in onCreate of Service

mWindowManager = (WindowManager) getSystemService(WINDOW_SERVICE);


    //Add the view to the window.
    params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            PixelFormat.TRANSLUCENT);

Problem was with FLAG_NOT_FOCUSABLE, use FLAG_NOT_TOUCH_MODAL instead.

But now again problem was that though I was able to get the keyboard with my floatingView but keypad was not coming for other apps, even back button stopped working.

So to fix this I used button on Floating UI which toggles between enabling keypad on floating UI and disabling that so that back button and keypad works for other apps.

I used the following code for the same:-

private void enableKeyPadInput(Boolean enable) {
    mWindowManager.removeViewImmediate(mFloatingView);

    if (enable) {
        params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
                PixelFormat.TRANSLUCENT);
    } else {
        params = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);
    }

    mWindowManager.addView(mFloatingView, params);
}

If true is passed to this method then keypad starts working. If false is passed then other apps starts working.

This is my workaround for the problem. Is there any other way to achieve the same which is better than this?