相关疑难解决方法(0)

使用ViewPager可见Fragment时,EditText会自动打开软键盘

我有一个Fragment(兼容版本)的EditText布局.我正在使用a ViewFlipper在片段之间翻转.当我遇到这个问题时Fragment,软键盘会自动打开.这不是我想要的.这是我试图阻止它或隐藏它.

尝试:

android:descendantFocusability="beforeDescendants" 
Run Code Online (Sandbox Code Playgroud)

在片段的主视图上

尝试:

android:windowSoftInputMode="stateHidden"
Run Code Online (Sandbox Code Playgroud)

android:windowSoftInputMode="stateAlwaysHidden"
Run Code Online (Sandbox Code Playgroud)

在活动的清单中

尝试:

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(mViewPager.getChildAt(position).getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)

在我的ViewPager的OnPageChangeListener上

尝试:

InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(voucherView.findViewById(R.id.redeem_mobile_number).getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)

在我的片段中的onCreateView中

尝试:

InputMethodManager imm = (InputMethodManager)mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getView().findViewById(R.id.redeem_mobile_number).getWindowToken(), 0);
Run Code Online (Sandbox Code Playgroud)

在我的片段中的onStart中

尝试:

voucherView.findViewById(R.id.redeem_mobile_number).clearFocus();
Run Code Online (Sandbox Code Playgroud)

在我的片段中的onCreateView中

在我看来,onPageChangeListener就是这样做的地方,因为其他调用在软键盘实际打开之前发生.任何帮助都会很棒.

android

30
推荐指数
3
解决办法
3万
查看次数

从EditText禁用软键盘但仍允许复制/粘贴?

嗨,我正在制作自定义拨号器,所以我创建了自己的输入板.

问题是如何禁用EditText 但仍然允许剪切/复制/粘贴?股票拨号器可以做到这一点.

我试过android:focusable="false"但它禁用剪切/复制(仍然可以粘贴).

我还试图以inputType编程方式禁用所有三个命令:

myEditText.setInputType(InputType.TYPE_NULL); //Can't cut/copy/paste
Run Code Online (Sandbox Code Playgroud)

从清单中禁用它也不起作用:

android:configChanges="orientation|keyboardHidden" //Keyboard still popped up
Run Code Online (Sandbox Code Playgroud)

有解决方案吗 谢谢

android android-edittext

29
推荐指数
4
解决办法
2万
查看次数

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

我正在开发使用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)

android android-softkeyboard android-edittext

27
推荐指数
3
解决办法
3万
查看次数

键盘会自动出现在Nexus7版本4.2上

我有一个包含时间选择器的对话框.在我所有的其他手机上,一切正常我单击按钮,出现对话框(包含时间选择器).比我设定的时间.

在Nexus 7版本的Android 4.2上.在横向模式下,当我单击按钮时,会出现对话框并自动显示键盘.我没有点击TimePicker.

任何人都知道我为什么在Nexus7上遇到这个问题.

编辑:代码如下

private DatePicker mDatePicker;

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
   mDatePicker = (DatePicker) view.findViewById(R.id.date_picker);
   mDatePicker.init(mDate.get(Calendar.YEAR), mDate.get(Calendar.MONTH), mDate.get(Calendar.DAY_OF_MONTH), this);
   mDatePicker.clearFocus();
}
Run Code Online (Sandbox Code Playgroud)

android dialog timepicker

5
推荐指数
1
解决办法
398
查看次数