2016-08-12 58 views
0

后改变其状态,我有一个问题,当我输入我不想键盘的文本自动改变,但空间键盘改变到原来的状态了。
例如,我想拨打我进入这个状态下,键盘的数字:enter image description here

但是,当我需要输入后面加一个空格的数量,键盘本身会自动更改:enter image description here

它是必要时用户自己可以改变键盘的状态,如果需要输入字符的话。我在编辑文本的文本上使用了一个蒙版。借助这个库设置掩码:MaskFormatter。一个面具的例子:
private static final String MASK = "99 AA 999999"; private EditText mInputCertificate; @Override public void setViews(View rootView, Bundle savedInstanceState) { // Some code mInputCertificate = (EditText) rootView.findViewById(R.id.input_car_certificate); MaskFormatter maskFormatter = new MaskFormatter(MASK, mInputCertificate); mInputCertificate.addTextChangedListener(maskFormatter); }

有办法解决这个问题吗?键盘空格

+0

您为EditText添加了inputType? – Esperanz0

+0

在xml文件中没有设置此选项,并且我下载并构建了类似java类的应用程序的库,它删除了类CharInputType中的替换键盘。 – metalink

回答

0

我做了我的自定义TextWatcher为EditText上:

private String getString (String s) { 
    String newValue = s.replaceAll("\\s", ""); 
    /*if (newValue.length() < 2 || newValue.length() >= 4) { 
     mEditText.setInputType(InputType.TYPE_CLASS_NUMBER); 
    } else { 
     mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); 
    }*/ 
    StringBuilder builder = new StringBuilder(); 
    for (int i =0; i < newValue.length(); i++) { 
     if (i == 2 || i == 4) { 
      builder.append(' '); 
      builder.append(newValue.charAt(i)); 
     } else { 
      builder.append(newValue.charAt(i)); 
     } 
    } 
    return builder.toString(); 
} 

@Override 
public void afterTextChanged(Editable s) { 
    Log.d("EDITTEXT", "getEditable " + s); 
    String text = getString(s.toString()); 
    mEditText.removeTextChangedListener(this); 
    mEditText.getText().clear(); 
    mEditText.append(text.toUpperCase()); 
    mEditText.addTextChangedListener(this); 
    mEditText.setSelection(mEditText.length()); 
} 

这为我工作。我用.append(SomeText)代替.setText(SomeText)。