如何在焦点更改时停止自动显示软键盘(OnStart 事件)
我正在使用 Android 2.2 开发平板电脑。
我有一个用于新的可编辑实例的表单。当可编辑时,我想阻止用户编辑某些字段。我在 onStart
事件中管理此操作,设置 txt.setFocusableInTouchMode(false)
。 这会将焦点强制到我的表单中下一个可聚焦的 EditText
(这很棒),但是在运行时,软键盘会自动出现在具有焦点的 EditText
上。 有人知道如何阻止这个吗?
代码如下(在 onStart
事件中调用):
private void PopulateFields(){
TextView txtTitle = (TextView) this.findViewById(R.id.txtEquipmentEditTitle);
AutoCompleteTextView txtMake = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditMake);
AutoCompleteTextView txtModel = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditModel);
EditText txtDesc = (EditText) this.findViewById(R.id.txtEquipmentEditDesc);
TextView txtDeptKey = (TextView) this.findViewById(R.id.txtEquipmentEditDeptKey);
EditText txtSerial = (EditText) this.findViewById(R.id.txtEquipmentEditSerialNo);
EditText txtBarCode = (EditText) this.findViewById(R.id.txtEquipmentEditBarCode);
txtTitle.setText("Edit Equipment");
txtMake.setText(make);
txtModel.setText(model);
txtDesc.setText(desc);
txtDeptKey.setText(Integer.toString(deptKey));
txtSerial.setText(serial);
txtBarCode.setText(barCode);
txtMake.setEnabled(false);
txtModel.setEnabled(false);
txtDesc.setEnabled(false);
txtMake.setClickable(false);
txtMake.setFocusableInTouchMode(false);
txtModel.setFocusableInTouchMode(false);
txtDesc.setFocusableInTouchMode(false);
txtMake.setFocusable(false);
txtModel.setFocusable(false);
txtDesc.setFocusable(false);
}
I am developing for a tablet using Android 2.2.
I have a form which I am using for new and editable instances. When editable, I want to stop the user from editing certain fields. I manage this in my onStart
-event, setting the txt.setFocusableInTouchMode(false)
.
This forces the focus to the next focusable EditText
in my form (which is great), but when running, the soft keyboard automatically appears for the EditText
with the focus.
Anybody know how to stop this?
Here's the code (called in the onStart
event):
private void PopulateFields(){
TextView txtTitle = (TextView) this.findViewById(R.id.txtEquipmentEditTitle);
AutoCompleteTextView txtMake = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditMake);
AutoCompleteTextView txtModel = (AutoCompleteTextView) this.findViewById(R.id.autEquipmentEditModel);
EditText txtDesc = (EditText) this.findViewById(R.id.txtEquipmentEditDesc);
TextView txtDeptKey = (TextView) this.findViewById(R.id.txtEquipmentEditDeptKey);
EditText txtSerial = (EditText) this.findViewById(R.id.txtEquipmentEditSerialNo);
EditText txtBarCode = (EditText) this.findViewById(R.id.txtEquipmentEditBarCode);
txtTitle.setText("Edit Equipment");
txtMake.setText(make);
txtModel.setText(model);
txtDesc.setText(desc);
txtDeptKey.setText(Integer.toString(deptKey));
txtSerial.setText(serial);
txtBarCode.setText(barCode);
txtMake.setEnabled(false);
txtModel.setEnabled(false);
txtDesc.setEnabled(false);
txtMake.setClickable(false);
txtMake.setFocusableInTouchMode(false);
txtModel.setFocusableInTouchMode(false);
txtDesc.setFocusableInTouchMode(false);
txtMake.setFocusable(false);
txtModel.setFocusable(false);
txtDesc.setFocusable(false);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
也许这会对您有所帮助:
首次创建或调用 Activity 时,将此方法放入
activity
的onCreate()
方法中。Maybe this will help you:
Put this method in the
onCreate()
method of youractivity
when the activity is first created or called.我们可以通过以下方式隐藏
设备键盘
,这完全取决于情况的需要_第一种方式_
第二种方式_
InputMethodManager
第三种方式_
代表以上所有方式_你还可以在应用程序
s
manifest`文件中定义windowSoftInputMode
_希望这对大家有帮助!
We can Hide the
device Keybord
by following ways which totally depends on the need of situation_First Way_
Second Way_
InputMethodManager
Third Way_
Behalf of all of the above ways_ you can also define
windowSoftInputMode
in applications
manifest` file_I hope this will help all!
如果您希望将其用于特定的
EditText
,那么这将起作用。editText.setShowSoftInputOnFocus(false);
If you want this for a particular
EditText
this will work.editText.setShowSoftInputOnFocus(false);
这就是答案:
在 AndroidManifest.xml 中向 Activity 添加一个属性:
this is the answer:
In your AndroidManifest.xml add an attribute to the Activity: