gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 22:00:47 27 4
gpt4 key购买 nike

我正在为使用 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);
}

最佳答案

也许这会对你有所帮助:

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

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

关于android - 如何在焦点更改时停止软键盘自动显示(OnStart 事件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5221622/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com