use*_*915 24 android android-softkeyboard android-edittext
我已经到了这一点,这让我在那里,但并不完全.我有一个拨号器Fragment,其中包含所有常用Button的输入数字,包括退格键,因此我不需要软键盘.我还想让用户能够粘贴文本(长按...默认情况下工作正常),以及编辑已输入的内容,因此我需要光标.
我找到的最简单的方法是确保软键盘不会弹出,如果用户点击内部EditText是设置inputType为null - 但这也会杀死光标.
那么,我如何声明我EditText应该启动哪些命令以使我的EditText字段永远不会显示软键盘,无论用户尝试什么,但仍然保留粘贴功能和光标?
我也尝试android:windowSoftInputMode="stateAlwaysHidden"过我的清单,但无济于事.
Edd*_*van 38
这对我有用:
// 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;
}
});
Run Code Online (Sandbox Code Playgroud)
小智 6
我终于找到了一个(对我来说)工作解决方案.
第一部分(在onCreate中):
// Set to TYPE_NULL on all Android API versions
mText.setInputType(InputType.TYPE_NULL);
// for later than GB only
if (android.os.Build.VERSION.SDK_INT >= 11) {
// this fakes the TextView (which actually handles cursor drawing)
// into drawing the cursor even though you've disabled soft input
// with TYPE_NULL
mText.setRawInputType(InputType.TYPE_CLASS_TEXT);
}
Run Code Online (Sandbox Code Playgroud)
另外,android:textIsSelectable需要设置为true(或在onCreate中设置),并且EditText不能专注于初始化.如果您的EditText是第一个可聚焦的视图(在我的情况下是它),您可以通过将它放在它上面来解决这个问题:
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true" >
<requestFocus />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
您可以在Grapher应用程序中看到此结果,该应用程序是免费的,可在Google Play中使用.
| 归档时间: |
|
| 查看次数: |
33729 次 |
| 最近记录: |