For e.g. an EditText it is normal to specify android:inputType="numberDecimal" for a text field supposed to contain a decimal number. But this assumes that '.' is used as the decimal separator and in some countries ',' is used instead. Is it possible to specify in xml that the users locale needs to be considered or do I have to do it manually in my code?
This is known bug, see here for more information.
A possible workaround is to set android:inputType="numberDecimal" (so the digit keyboard will be opend) and android:digits="0123456789.," (so the comma can be entered into the EditText). Then add a TextChangedListener and do something like Double.parseDouble(editable.toString().replace(',', '.')); in afterTextChanged.
Related
I have used the android:digits in editText view to accept only letters, but when i set this property then single line restrict is not working.
It always creates new line when i enter more text.
If i remove the digits property, single line restrict works.
android:inputType="text"
android:maxLines="1"
android:digits="abcdefghijklmnopqrstuvwxyz"
android:singleLine="true"
will work for you. But since it is deprecated it is not advisable to use it.
But it is the easiest solution for it.
When inputtype is used as textPassword, user was able to entire emoji in edit text. If I use both textpassword and textEmailAddress, then passwords are visible. Is there any easy way to achieve this without using textwatcher. The password field can allow other special characters also.
Please note that I am trying to remove emoji by setting the input type. I am not looking for solutions with regular expressions/textwatcher/filters. If the field is not password type I would have used textEmailAddress to avoid emoji option on keyboard
This allow character only a to z and A to Z :
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:inputType="textPassword"/>
Use this in your Password EditText XML file
android:inputType="textPassword|text"
Look more about input methods here
Also, you can use RegularExpression to check whether your password is valid or not.
I am making a calculator and I want to make sure that user is able to enter a "Negative Decimal Number" I see the option in the xml file separately for example in order to put the Decimal Number, the EditText's inputType must be numberDecimal and for negative number the inputType must be "numberSigned" but I need both. If I choose inputType as "text" then user is able to enter anything which throws an exception if it's not a number. I am not sure how to fix that either.
You can use both with the "|" operator. Just specify "numberSigned|numberDecimal".
Add this in the layout of the EditText:
android:digits="0123456789-."
You can specify more there, for example if you want the user to input sin() functions.
As #a11n says, you can use the pipe operator to specify both:
<EditText
...
android:inputType="numberSigned|numberDecimal"
... />
Valid numbers: positive and negative decimal and whole numbers.
Some phones have the decimal and negative in the same button and makes it unable to do negatives. I figured out a way you could separate the buttons by simply adding:
android:inputType="numberSigned|numberDecimal|textPersonName"
android:digits="0123456789.-"
That way you still have the number keyboard layout but the negative and decimal buttons will be separate and you cannot use any other digit that messes up the app.
In Android, while entering password the text is displayed. Is there any way to hide the text programmatically?
Set the inputType to password. Either in the xml (as an attribute of your EditText):
android:inputType="textPassword"
or in your program:
yourETView.setInputType(InputType.TYPE_TEXT_VARIATION_PASSWORD);
In your XML that holds the input field use the following:
android:inputType="textPassword"
it's depend on the real device. means In device whatever the user use the devices have 1 one option was available in the setting for hide/show the text while typing text in password field so no need to worry about it, for accept text as password you can set the input type of edittext like this way
android:inputType="textPassword"
in xml layout file
I'm trying to choose correct inputType in my adress dialog streetNumber field.
I want to show numeric keyboard first, but then let user also to input alphabetic characters
for some very special cases. Closer to this is inputType datetime,
but this doesn't allow to enter alphabetic characters. So how to set my streetNumber field correctly?
Use android:inputType="textPostalAddress"
The EditText inherits from TextView and shares its input type attributes with it. They can be found here in the official documentation.
Maybe the input type textPostalAddress would be suitable for your need. If not, plenty of other types are available. The XML attribute that allows setting this type is android:inputType="the type you have chosen".
See if this can help you
myEditText.setRawInputType(Configuration.KEYBOARD_QWERTY)