我正在寫使用下面的代碼來在運行的應用程序在屏幕上繪製一個EditText的應用程序:的Android - 鍵盤沒有出現在浮動窗口
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是:
<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:
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中看到,沒有任何反應。到目前爲止,我發現,顯示鍵盤的唯一方法是使用:
getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(0, 0);
,但似乎鍵入到屏幕上,而不是進入的EditText。 我也試過顯示edittext時清晰可調焦,但無濟於事。
我猜這個問題是因爲我使用的是「浮動窗口」,但必須有一種方法來使這項工作成爲浮動計算器等應用程序存在於需要輸入的playstore上。任何人都有任何想法?我難倒:(
你過得好從編輯文本的價值? – rup35h