我正在开发使用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);
}
答案 0 :(得分:62)
也许这会对你有所帮助:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
答案 1 :(得分:11)
我们可以通过以下方式隐藏device Keybord
,这完全取决于情况的需要_
First Way_
EditText userId;
/*
* When you want that Keybord not shown untill user clicks on one of the EditText Field.
*/
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Second Way_
InputMethodManager
/*
* When you want to use service of 'InputMethodManager' to hide/show keyboard
*/
InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
inputManager.hideSoftInputFromWindow(userId.getWindowToken(),
InputMethodManager.HIDE_NOT_ALWAYS);
Third Way_
/*
* Touch event Listener
* When you not want to open Device Keybord even when user clicks on concern EditText Field.
*/
userId.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View v, MotionEvent event) {
int inType = userId.getInputType(); // backup the input type
userId.setInputType(InputType.TYPE_NULL); // disable soft input
userId.onTouchEvent(event); // call native handler
userId.setInputType(inType); // restore input type
userId.setFocusable(true);
return true; // consume touch even
}
});
代表上述所有方法_您还可以在应用程序windowSoftInputMode
manifest`文件中定义s
_
<manifest ... >
<application ... >
<activity
android:windowSoftInputMode="stateHidden|stateAlwaysHidden"
... >
<intent-filter>
...
</intent-filter>
</activity>
</application>
</manifest>
我希望这会对所有人有所帮助!
答案 2 :(得分:3)
如果您想要特定的EditText
,这将有效。
editText.setShowSoftInputOnFocus(false);
答案 3 :(得分:-1)
这就是答案: 在AndroidManifest.xml中为Activity添加一个属性:
<activity android:name=".MyActivity" android:windowSoftInputMode="adjustPan"> </activity>