如何在焦点更改时停止软键盘自动显示(OnStart 事件)

How to stop Soft keyboard showing automatically when focus is changed (OnStart event)(如何在焦点更改时停止软键盘自动显示(OnStart 事件))
本文介绍了如何在焦点更改时停止软键盘自动显示(OnStart 事件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在为使用 Android 2.2 的平板电脑进行开发.

I am developing for a tablet using Android 2.2.

我有一个用于新的可编辑实例的表单.当可编辑时,我想阻止用户编辑某些字段.我在我的 onStart-事件中管理它,设置 txt.setFocusableInTouchMode(false).这会强制将焦点移到我的表单中的下一个可聚焦的 EditText 上(这很棒),但是在运行时,软键盘会自动出现在具有焦点的 EditText 上.有人知道如何阻止这种情况吗?

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?

这是代码(在 onStart 事件中调用):

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);
}

推荐答案

也许这会对你有所帮助:

Maybe this will help you:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);

当第一次创建或调用活动时,将此方法放在你的activityonCreate()方法中.

Put this method in the onCreate() method of your activity when the activity is first created or called.

这篇关于如何在焦点更改时停止软键盘自动显示(OnStart 事件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Prevent enter key on EditText but still show the text as multi-line(防止在 EditText 上输入键,但仍将文本显示为多行)
Android keyboard next button issue on EditText(EditText上的Android键盘下一个按钮问题)
When the soft keyboard appears, it makes my EditText field lose focus(当软键盘出现时,它使我的 EditText 字段失去焦点)
android how to make text in an edittext exactly fixed lines(android如何在edittext中制作文本完全固定的行)
How to use regular expression in Android(如何在 Android 中使用正则表达式)
Filter list view from edit text(从编辑文本中过滤列表视图)