問題描述
我正在為使用 Android 2.2 的平板電腦進(jìn)行開發(fā).
I am developing for a tablet using Android 2.2.
我有一個(gè)用于新的可編輯實(shí)例的表單.當(dāng)可編輯時(shí),我想阻止用戶編輯某些字段.我在我的 onStart
-事件中管理它,設(shè)置 txt.setFocusableInTouchMode(false)
.這會(huì)強(qiáng)制將焦點(diǎn)移到我的表單中的下一個(gè)可聚焦的 EditText
上(這很棒),但是在運(yùn)行時(shí),軟鍵盤會(huì)自動(dòng)出現(xiàn)在具有焦點(diǎn)的 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
事件中調(diào)用):
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);
}
推薦答案
也許這會(huì)對(duì)你有所幫助:
Maybe this will help you:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
當(dāng)?shù)谝淮蝿?chuàng)建或調(diào)用活動(dòng)時(shí),將此方法放在你的activity
的onCreate()
方法中.
Put this method in the onCreate()
method of your activity
when the activity is first created or called.
這篇關(guān)于如何在焦點(diǎn)更改時(shí)停止軟鍵盤自動(dòng)顯示(OnStart 事件)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!