EditText input type textCapSentences not working o

2020-08-10 07:18发布

问题:

I have implemeted android:inputType="textAutoComplete|textCapSentences" in my xml code. When I run it on kitkat, textCapSentence works fine but when build is run on Lollipop device it does not work. Anybody knows how to solve it.

回答1:

Hi this is because in lollipop if you have disabled Auto - Capitalization in keyboard settings then you can't enable it programmatically.

here are the steps:-

  • Tap icon of ‘Settings’ on the Home screen of your Android Lollipop Device
  • At the ‘Settings’ screen, scroll down to the PERSONAL section and tap the ‘Language & input’ section.
  • At the ‘Language & input’ section, select your keyboard(which is marked as current keyboard).
  • Now tap the ‘Preferences’.
  • Tap to check the ‘Auto – Capitalization’ to enable it.
  • That’s all!


回答2:

Set this way,

EditText input = (EditText).findViewById(R.id.ID);
input.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);


回答3:

Add these two attributes. It works.

 android:capitalize="sentences"
 android:inputType="textCapSentences"


回答4:

Set input type in XML as well as in JAVA file like this,

In XML,

android:inputType="textCapSentences"

and in JAVA file,

edittext.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

This worked for me and make sure your keyboard's Auto-Capitalization setting is Enabled.



回答5:

On which devices and OS specific versions are you trying. Sometime the manufactures are overriding the "InputMethod" on the OS level and it's just not working.

you can also make a test by taking the sources of the EditText from google code and compile it as your EditTextCustom and see if it's working.