I\'m working on a little personal todo list app and so far everything has been working quite well. There is one little quirk I\'d like to figure out. Whenever I go to add a
Earlier it used to be android:capitalize="words"
, which is now deprecated. The recommended alternative is to use android:inputType="textCapWords"
Please note that this will only work if your device keyboard Auto Capitalize Setting enabled.
To do this programatically, use the following method:
setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);
Programmatically
TextView firstline = (TextView) findViewById(R.id.firstline);
firstline.setAllCaps(true);
Set input type in XML as well as in JAVA file like this,
In XML,
android:inputType="textMultiLine|textCapSentences"
It will also allow multiline and in JAVA file,
edittext.setRawInputType(InputType.TYPE_CLASS_TEXT|InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
make sure your keyboard's Auto-Capitalization setting is Enabled.
Just use android:inputType="textCapWords"
in your EditText element.
For example:
<EditText
android:id="@+id/txtName"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="0.7"
android:inputType="textCapWords"
android:textColorHint="#aaa"
android:hint="Name Surname"
android:textSize="12sp" />
Refer to the following link for reference: http://developer.android.com/reference/android/widget/TextView.html#attr_android%3ainputType
i founded and my solution : you have 2 way to resolve it in java :
testEditText.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_FLAG_CAP_WORDS);
and xml :
<EditText
android:id="@+id/mytxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textCapWords"
android:textSize="12sp" />
I can assure you both the answers will make first letter capital and will not make edittext single line.
If you want to do it in XMl below is the code
android:inputType="textCapWords|textCapSentences"
If want to do it in activity/fragment etc below is the code
momentTextView.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS | InputType.TYPE_TEXT_FLAG_MULTI_LINE)
PS: If you are having nay other property also you can easily add it with a pipe "|" symbol, just make sure there is no space in xml between the attribute properties