Run*_*gen 27 android android-softkeyboard android-edittext
我正在开发使用Android 2.2的平板电脑.
我有一个表单,我用于新的和可编辑的实例.可编辑时,我想阻止用户编辑某些字段.我在我的onStart-event中设置了这个,设置了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);
}
Run Code Online (Sandbox Code Playgroud)
Mob*_*ion 63
也许这会对你有所帮助:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Run Code Online (Sandbox Code Playgroud)
Rup*_*dav 12
我们可以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);
Run Code Online (Sandbox Code Playgroud)
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);
Run Code Online (Sandbox Code Playgroud)
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
}
});
Run Code Online (Sandbox Code Playgroud)
代表上述所有方法_您还可以windowSoftInputMode在应用程序s清单`file_中定义
<manifest ... >
<application ... >
<activity
android:windowSoftInputMode="stateHidden|stateAlwaysHidden"
... >
<intent-filter>
...
</intent-filter>
</activity>
</application>
</manifest>
Run Code Online (Sandbox Code Playgroud)
我希望这对所有人都有帮助!
| 归档时间: |
|
| 查看次数: |
28773 次 |
| 最近记录: |