EditText textCapSentences does not work - android

I try to make text starts with uppercase first letter.
Using attr inputType
<EditText
android:id="#+id/add_user_fname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="#dimen/margin_size_small"
android:inputType="textCapSentences|textPersonName"
android:capitalize="sentences"
android:layout_toRightOf="#id/user_avatar"
android:hint="#string/add_user_fname"
android:maxLength="#integer/name_max_length"
android:singleLine="true"
android:textSize="#dimen/text_size_small" />
and set in code
userFnameEditText.setInputType(InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
but nothing works.
All of this places in DialogFragment.
Updated
I removed setInputType in code and set only inputType="textCapSentences". It works on Android 4, but doesn't work on Samsung Android 5

I had the same problem. But, I found a solution that help me: Be sure that your "Auto Capitalization" settings is checked on keyboard settings. This works on Nexus 4.
Reference: http://www.ercanbaran.com/textcapsentences-not-working/

Edited
Try it in your java file
TextView txtCapitalize = (TextView) findViewById(R.id.txtCapitalize);
txtCapitalize.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_WORDS);

You should add this line captilaize your letter in EditText
android:inputType="textCapSentences"
I hope this is helpful. ThankYou

To inform you android:capitalize="sentences" is deprecated, So as suggested by other answers you can either use
android:inputType="textCapSentences"
OR
android:inputType="textCapWords"
Both works ! But one for sentence and one for words.

Try this:
android:inputType="textCapSentences"
and
android:capitalize="sentences"
remove textPersonName from xml.

if you add both
android:capitalize="sentences"
and android:inputType="text", in this case it take first and input will not captalized.
android:inputType="textCapSentences"

Related

android:imeOptions. Button not showing up

I tried setting android:imeOptions to actionSend, actionSearch. But there's no "Send" or "Search" button on the keyboard, just usual "Enter" key. I also tried setting different input types. (I'm working with HTC Sensation XL.) What's wrong?
I'd suggest switching your EditText to singleLine mode
Currently in Android Studio 2.2.3 if you use
android:singleLine="true"
IDE gives a warning that it has been deprecated use maxlines instead.
android:maxLines="1"
However maxLines does not solve the problem. The solution is to just add the attribute inputType. Example :
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/actionDoneDemo"
android:layout_below="#id/nameET"
android:imeOptions="actionDone"
android:hint="Action Done Demo"
android:inputType="text"/>
Try these actionDone imeOption doesn't work on EditText in Android 2.3
if it is not supported read How do I handle ImeOptions' done button click?. May be the HTC implemented their own soft keyboard which ignores the imeOptions
Just do in xml:
<EditText android:imeOptions="actionSearch"
android:inputType="text"/>
Happy Coding!!

how to get "Done" button in android keyboard?

I created many emulators but i did not get 'Done' button on emulator.any ideas to solve this problem?
I have attached the screenshot Emulator' Screenshot
Just add two lines in xml:
android:imeOptions="actionDone"
android:singleLine="true"
Done
Try adding android:imeOptions="actionDone" to your EditText.
android:singleLine="true" has been deprecated. Alternatively you could use this:
android:inputType="text"
android:maxLines="1"

how to set en EditText to both password and numeric keyboard

I've the following EditText which it's characters need to be hidden as it is a password. I can do this with the following.
<EditText
android:id="#+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Please Enter Password/Pin"
android:inputType="textPassword"
>
I would like to set the keyboard to numeric as all passwords are numbers, but when i do the following the numbers are displayed. How can i acheive both?
passwordPin = (EditText)findViewById(R.id.password);
passwordPin.setInputType(InputType.TYPE_CLASS_NUMBER);
Try this.
android:inputType="textPassword|number"
Try the following line for EditText
android:inputType="textPassword|number"
Looking through Eclipse, you can also use the following, not sure how backwards compatible it is however.
android:inputType="numberPassword"
Solved.
android:inputType="textPassword|number"
android:password="true"
You can do it programmatically as long as password is now deprecated. Try this:
passwordPin = (EditText)findViewById(R.id.password);
passwordPin.setInputType(InputType.TYPE_CLASS_NUMBER);
editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
I ran into this same requirement and solved it this way:
In XML:
android:inputType="number|numberPassword"
Programmatically:
editText.setInputType(InputType.TYPE_CLASS_NUMBER || InputType.TYPE_NUMBER_VARIATION_PASSWORD)
Hope this helps :D

Edit Text without Autocorrect

I want an EditText without the autocorrection.
I have set the textNoSuggestions inputType, as shown:
<EditText
android:id="#+id/txtTarga"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Targa"
android:inputType="textNoSuggestions|textCapCharacters" >
The capitalize flag works, but it is still autocorrecting.
How can I disable it?
inputType textVisiblePassword will do the trick (most of the times, because as Commonsware pointed out, it stays a request and you'll might find yourself finding devices where it works, and devices where it doesn't work)
android:inputType="textNoSuggestions"
according to this, inputType attribute may or may not be supported by some devices .
However, this seems to work more often
android:inputType="textNoSuggestions|textVisiblePassword"
You could try by code, something like this:
EditText edittext = (EditText)findViewById(R.id.txtTarga);
edittext.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
In Xml
<EditText
android:id="#+id/password"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:hint="password"
android:imeOptions="actionDone"
android:inputType="textPassword"
android:singleLine="true"
/>
In java source code
// casting done from EditText to TextView
TextView mPassword = (TextView) findViewById(R.id.password);
No idea why is this. But works fine.
textNoSuggestions does not work in every keyboard. The accepted answer inputType="textVisiblePassword" works but it removes emoji's from most keyboards.
I found that setting inputType="textUri" works and keeps the ability to add emojis.

Android Ice Cream Sandwich Edittext: Disabling Spell Check and Word Wrap

Whilst testing on the Android Emulator running Android 4.0 (Ice Cream Sandwich), I have noticed that the Edittext does some quite strange things.
Firstly, it underlines every word identified as "misspelt" in red. How do I disable this?
Secondly, although in the layout XML I have specified android:scrollHorizontally="true" word-wrap is enabled: how do I disable this as well? Here is the Layout XML code for the Edittext:
<EditText
android:id="#+id/editor"
android:layout_width="40dp"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_below="#+id/toolbar"
android:layout_toRightOf="#+id/toolbarleft"
android:paddingBottom="0dp"
android:paddingRight="0dp"
android:scrollHorizontally="true"
android:text=""
android:inputType="textMultiLine" >
<requestFocus />
</Edittext>
Here is an example of the spell checker I need to disable:
(source: abstract-thoughts.com)
Thanks very much!
Disabling Spell-Checking
In order to get rid of spell checking you must specify the EditText's InputType in the XML as the following:
android:inputType="textNoSuggestions"
However, my EditText needed also to be multiline, so I have added the following line to the EditText's XML:
android:inputType="textMultiLine|textNoSuggestions"
Disabling Word-Wrap
As noted, the XML attribute android:scrollHorizontally="true" does not work. However, strangely, if it is done through Java it does work. Here is the necessary code to achieve no word wrapping:
mEditText.setHorizontallyScrolling(true);
Disabling Spell-Checking in EditText.
In Android 4.0+ sometimes I get a red underline in my Textview so i add the property ...
android:inputType="textNoSuggestions"
textNoSuggestions: to indicate that the IME should not show any
dictionary-based word suggestions.
Here is a list of possible properties that we can define in :
android:inputType
Disabling Word-Wrap
remember that the property android:scrollHorizontally="true" doesn't work, so this is the solution:
mEditText.setHorizontallyScrolling(true);
In your Java class you can add to the Edittext object...
wire1type = (EditText)findViewById(R.id.wire1type);
wire1type.setInputType( ~(InputType.TYPE_TEXT_FLAG_AUTO_CORRECT) );
This clears out the autocorrect flag and will work in API 4.
android:inputType="textMultiLine|textPhonetic"
removed all red underlines for me.
android:inputType="textMultiLine|textNoSuggestions"
produces compilation error.
I use Android API 1.6.
Disabling the spell checker for general text input via code:
mEditText.setInputType(InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
remove android:inputType="" and all should be well.
To disable line wrapping you have to wrap (pun not intended) your EditText with an HorizontalScrollView and set your layout_width to match_parent.

Categories

Resources