問題描述
我已經(jīng)完成了 這個(gè) 這讓我走到了一半,但并不完全.我有一個(gè)撥號(hào)器 Fragment
,它有所有常用的 Button
來輸入數(shù)字,包括退格,所以我不需要軟鍵盤.我還想讓用戶能夠粘貼文本(長(zhǎng)按...默認(rèn)情況下可以正常工作),以及編輯輸入的內(nèi)容,所以我需要光標(biāo).
I've come about as far as this which gets me halfway there, but not quite.
I have a dialer Fragment
that has all the usual Button
s to enter a number including backspace, so I don't need the soft keyboard. I'd also like to give the user the ability to paste text (long click... works fine per default), as well as to edit what has been entered so I need the cursor.
如果用戶在 EditText
內(nèi)單擊,我發(fā)現(xiàn)確保不會(huì)彈出軟鍵盤的最簡(jiǎn)單方法是將 inputType
設(shè)置為 null - 但是也殺死光標(biāo).
The easiest way I found to make sure the soft keyboard doesn't pop up if the user clicks inside the EditText
is to set the inputType
to null - but that kills the cursor as well.
那么,我該如何聲明我的 EditText
以及我應(yīng)該啟動(dòng)什么樣的命令才能讓我的 EditText
字段永遠(yuǎn)不會(huì)顯示軟鍵盤,無論用戶嘗試什么,但仍保留粘貼功能和光標(biāo)?
So, how do I declare my EditText
and what kind of commands should I launch to have my EditText
field never ever show the soft keyboard no matter what the user attempts, but still retain paste functionality and the cursor?
我也在清單中嘗試了 android:windowSoftInputMode="stateAlwaysHidden"
,但無濟(jì)于事.
I've also tried android:windowSoftInputMode="stateAlwaysHidden"
in my manifest, but to no avail.
推薦答案
這對(duì)我有用:
// Update the EditText so it won't popup Android's own keyboard, since I have my own.
EditText editText = (EditText)findViewById(R.id.edit_mine);
editText.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
v.onTouchEvent(event);
InputMethodManager imm = (InputMethodManager)v.getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null) {
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
return true;
}
});
這篇關(guān)于Android在不丟失光標(biāo)的情況下從EditText隱藏軟鍵盤的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!