Android keyboard - start lowercase

人走茶凉 提交于 2019-11-28 09:02:51

问题


Is it possible to start android keyboard with lowercase when I click on EditText? Basically, what I want is to lowercase the first letter in EditText, but also to give user an possibility to make it uppercase if he want...

(EditText input is and must be multiline text)

EDIT:

            <EditText
                android:id="@+id/txt_str"
                android:inputType="text|textMultiLine"
                android:maxLines="1"
                android:layout_width="0dp"
                android:layout_weight="1"
                android:layout_height="match_parent"
                android:hint="@string/enter_txt_here"
                android:textIsSelectable="true"
                android:layout_marginRight="6dp"
                android:paddingLeft="6dp"
                android:paddingRight="6dp"
                android:textSize="17sp"
                android:textColor="#FFFFFF"
                android:textColorHint="#FFFFFF"
                android:gravity="center_vertical"
                android:background="@drawable/txt_card_selector"
                android:ellipsize="start" />

EDIT2
I think this is not possible when text must be multiline...


回答1:


Yes that is possible. Try researching the EditText Input Types.

For example you force the keyboard default state as lower case by simply:

EditText text = new EditText(context);
text.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_FLAG_MULTI_LINE);

Or if you want to force capitalization for every sentense:

EditText text = new EditText(context);
text.setInputType(android.text.InputType.TYPE_CLASS_TEXT | android.text.InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);

You can find a whole list types here.




回答2:


Using xml you can force keyboard to make lowercase

android:inputType="text|textEmailAddress"



回答3:


As this page says: Initial keyboard on lowercase

Set input type to email addres:

Text.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);



回答4:


Using

text.setInputType(text.InputType.TYPE_CLASS_TEXT | text.InputType.TYPE_TEXT_FLAG_MULTI_LINE);

or

text.setInputType(text.InputType.TYPE_CLASS_TEXT | text.InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);

Did not work for me. What actually did it was this:

text.setInputType(inputEditText.getInputType() | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS); // forced capitalization
text.setInputType(inputEditText.getInputType() & ~ InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS); // negate the flag


来源:https://stackoverflow.com/questions/20961585/android-keyboard-start-lowercase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!