問題描述
我正在編寫一個應(yīng)用程序,它使用以下代碼在正在運(yùn)行的應(yīng)用程序的屏幕上繪制編輯文本:
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" />
但是,專注于此并不會調(diào)出鍵盤.我還嘗試通過 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 中可以看出,盡管調(diào)用了它,但什么也沒發(fā)生.到目前為止,我發(fā)現(xiàn)顯示鍵盤的唯一方法是使用:
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);
但這似乎是在屏幕上輸入而不是在編輯文本中.當(dāng)顯示編輯文本時,我也嘗試過清晰可聚焦,但無濟(jì)于事.
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.
我猜這個問題是因?yàn)槲沂褂玫氖歉哟翱?,但必須有一種方法可以使這項(xiàng)工作成為可能,因?yàn)?Playstore 中存在浮動計(jì)算器等應(yīng)用程序,它們需要輸入.有人有什么想法嗎?我被難住了:(
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
這篇關(guān)于Android - 鍵盤未出現(xiàn)在浮動窗口中的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!