Android - 键盘没有出现在浮动窗口中 [英] Android - Keyboard not appearing in floating window

查看:454
本文介绍了Android - 键盘没有出现在浮动窗口中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写一个应用程序,它使用以下代码在屏幕上通过运行的应用程序绘制edittext:

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.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_PHONE,
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
                PixelFormat.TRANSLUCENT);

windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

windowManager.addView(mEditText, params);

edittext的xml是:

The xml for the edittext is:

<EditText
            android:id="@+id/mEditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:maxLines="3"
            android:inputType="textAutoComplete|text"
            android:focusable="true"
            android:focusableInTouchMode="true" />

然而,专注于此并不能打开键盘。我还尝试用onFocusListener以编程方式提出它:

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() {
            @Override
            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");
                }
            }
        });

但是,虽然从logcat中看到,但是没有任何反应。到目前为止,我发现显示键盘的唯一方法是使用:

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);

但这似乎是在屏幕上输入而不是在edittext中输入。
我在编辑文本显示时也尝试了明确的焦点,但无济于事。

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.

我猜这个问题是因为我正在使用浮动窗口但必须有一种方法使这项工作作为浮动计算器等应用程序存在于Playstore上接受输入..任何人都有任何想法?我很难过:(

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 :(

推荐答案

我的错...我意识到如果我删除WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE它工作正常。愚蠢的错误

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

这篇关于Android - 键盘没有出现在浮动窗口中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆