Android - Keyboard not appearing in floating window(Android - 键盘未出现在浮动窗口中)
问题描述
我正在编写一个应用程序,它使用以下代码在正在运行的应用程序的屏幕上绘制编辑文本:
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);
但这似乎是在屏幕上输入而不是在编辑文本中.当显示编辑文本时,我也尝试过清晰可聚焦,但无济于事.
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 - 键盘未出现在浮动窗口中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android - 键盘未出现在浮动窗口中
基础教程推荐
- Java Keytool 导入证书后出错,"keytool error: java.io.FileNotFoundException &拒绝访问" 2022-01-01
- “未找到匹配项"使用 matcher 的 group 方法时 2022-01-01
- 无法使用修饰符“public final"访问 java.util.Ha 2022-01-01
- 如何使用 Java 创建 X509 证书? 2022-01-01
- 减少 JVM 暂停时间 >1 秒使用 UseConcMarkSweepGC 2022-01-01
- 设置 bean 时出现 Nullpointerexception 2022-01-01
- 降序排序:Java Map 2022-01-01
- FirebaseListAdapter 不推送聊天应用程序的单个项目 - Firebase-Ui 3.1 2022-01-01
- Java:带有char数组的println给出乱码 2022-01-01
- 在 Libgdx 中处理屏幕的正确方法 2022-01-01