how to set en EditText to both password and numeric keyboard - android

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

Related

Password field with numeric keyboard on android [duplicate]

I have the following:
<EditText
android:inputType="number"
android:password="true"
....
</EditText>
I'm getting a warning that "android:password" is deprecated and that I should use inputType instead. Is there a way to specify inputType as number and password?
Set android:inputType="numberPassword"
See this Link
you should use TYPE_CLASS_NUMBER.
EDIT:
As this answer
android:inputType="textPassword|number"
ignore textPassword and only accept number but not password.
So you should use android:inputType="textPassword|number" with android:password="true".
that seems to be the only solution.
Just set your input type to this android:inputType="textPassword|number"

Android keyboard change enter key

How can I change EditText keyboard enter key like this ?
The solution for me was adding these two lines in the XML of Edittext
android:imeOptions="actionDone"
android:inputType="text"
Thx everyone.
Android have "android:imeOptions" to specify the keyboard action button
1. android:imeOptions="actionGo"
2. android:imeOptions="actionDone"
3. android:imeOptions="actionNext"
4. android:imeOptions="actionPrevious"
5. android:imeOptions="actionSend"
...and more,
you can use based on requirement
Try using android:imeOptions with your EditText in your layout file:
android:imeOptions="actionGo"
use this in your xml where you have define your edittext android:imeOptions="actionDone"

EditText textCapSentences does not work

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"

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.

How do I specify EditText inputType as number and password?

I have the following:
<EditText
android:inputType="number"
android:password="true"
....
</EditText>
I'm getting a warning that "android:password" is deprecated and that I should use inputType instead. Is there a way to specify inputType as number and password?
Set android:inputType="numberPassword"
See this Link
you should use TYPE_CLASS_NUMBER.
EDIT:
As this answer
android:inputType="textPassword|number"
ignore textPassword and only accept number but not password.
So you should use android:inputType="textPassword|number" with android:password="true".
that seems to be the only solution.
Just set your input type to this android:inputType="textPassword|number"

Categories

Resources