简体   繁体   中英

Soft input layout doesn't change as intended

I have a problem with my android soft input layout.

What I need is a phone layout which only accepts numeric values. I have done this before by modifying xml:

android:inputType="phone"
android:digits="0123456789"

and it worked like a charm.

Now the current EditText is generated dynamically, and I have to do it programmatically.

I've already tried

mEditTextET.setInputType(InputType.TYPE_CLASS_PHONE | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
mEditTextET.setKeyListener(DigitsKeyListener.getInstance("0123456789"));

but it shows text layout instead of phone layout.

Any ideas?

    mEditTextET.setInputType(InputType.TYPE_CLASS_NUMBER);          
    mEditTextET.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);           
    mEditTextET.setKeyListener(DigitsKeyListener.getInstance(false,true));

Try this way.Hope it will solve your problem only setInputType like this in your EditText

mEditTextET.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_CLASS_PHONE);
mEditTextET.setKeyListener(DigitsKeyListener.getInstance("0123456789"));

Device s4 Os : 4.4.2 **设备s4 Os:4.4.2 **

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM