How open specific page of keyboard? - android

In one of my edittext fields users can enter numeric values and colons. These keys are part of one specific page of the keyboard. I would like to open that specific page if the users enters the corresponding edittext field. If there's a XML attribute for the layout it would be even better.
Many thanks in advance.

To display pure numeric keyboard use android:inputType="phone"
The android:inputType="time" is the best options for time input. It
will let you input numbers and colon ':'.
For 'Known Distance' and 'Distance to estimate' you can use
android:inputType="number|numberDecimal". It will let you input
numbers with dots i.e double or floats.
You can use android:inputType="number" for Numbers. Here is an example of EditText which opens phone with digits-numbers Keyboard.
<EditText
android:id="#+id/test"
android:inputType="phone"
android:layout_height="wrap_content"
android:layout_width="wrap_content" />
Here is a small example of using inputType in layout.
You can use following values in inputType field.
none
text
textCapCharacters
textCapWords
textCapSentences
textAutoCorrect
textAutoComplete
textMultiLine
textImeMultiLine
textNoSuggestions
textUri
textEmailAddress
textEmailSubject
textShortMessage
textLongMessage
textPersonName
textPostalAddress
textPassword
textVisiblePassword
textWebEditText
textFilter
textPhonetic
textWebEmailAddress
textWebPassword
number
numberSigned
numberDecimal
numberPassword
phone
datetime
date
time
Here is detailed explanation about it.

According to InputType of EditText in Android and other answers here, the only way is to make your own class of keyboard. Or find some ready on the net.

Related

Can I use numberPassword input type and still see the input?

Can I use numberPassword as input type and still see the input?
My goal is to have a 0-9 keyboard with as few as possible other keys (that's why I prefered numberPassword over phone), but the user should still be able to see what he just typed.
This is what I have, but right now the passwords are hidden behind asterisks.
android:digits="1234567890"
android:inputType="numberPassword"
Note: I also tried setInputType(InputType.TYPE_NUMBER_VARIATION_PASSWORD), which made the input visible, but changed the keyboard from numbers-only to a regular keyboard. I need they keyboard to display numbers-only though.
In Java, just do this:
edittext.setTransformationMethod(PasswordTransformationMethod.getInstance());
If you wanted to hide the password later on, you would just do this:
editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance());
This did the job:
uEditText = (EditText) findViewById(R.id.editText);
uEditText.setTransformationMethod(null);
There are different ways you can solve this problem
You can use use TextInputEditText with TextInputLayout like below
<android.support.design.widget.TextInputLayout
android:id="#+id/etPasswordLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:passwordToggleEnabled="true"
android:layout_marginBottom="#dimen/login_spacing_bottom">
<android.support.design.widget.TextInputEditText
android:id="#+id/etPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="#string/fragment_login_password_hint"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
With passwordToggleEnabled, you can toggle between asterisk and password values
You can use the Transformation class to toggle password asterisk and value like below
edittextObject.setTransformationMethod(PasswordTransformationMethod.getInstance());
You can create a custom keyboard with the values you want to display in your keyboard. You can see how to achieve this in this tutorial I wrote about custom keyboard

Why is EditText repeating text when entering a not allowed char defined by "android:digits" attribute?

My Activity has an EditText as defined bellow:
<EditText
android:id="#android:id/text1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:digits="0123456789.:"
/>
The allowed input should be ., : and numbers. But if a not allowed char is typed when the EditText is empty the text starts to be duplicated.
For example, assuming the EditText is empty, type the following sequence: abc123.
On my device the result is 1112123, but the expected result should be just 123.
As this should be as simple as possible, I would not like to use an InputFilter.
In fact this has something to do with the default InputFilter for android:digits (DigitsKeyListener), the android:inputType="text" and the current Keyboard.
The keyboard suggestions can be messy when using android:digits. As I do not need keyboard suggestions for this specific EditText I changed the android:inputType to textNoSuggestions and now it is working as expected.

Phone pad and Qwerty keypad in android

I am looking to implement both phone pad and keypad in Android.As, per my requirement when the EditText is selected a default phone pad should be shown. But the user must be able to input alphabets also. Please suggest me a way to implement this.
<EditText
android:id="#+id/editTextref1"
android:layout_width="210dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:ellipsize="start"
android:hint="#string/custom1"
android:imeOptions="actionNext|actionDone"
android:inputType="text"
android:nextFocusDown="#+id/editTextref2"
android:shadowDy="10"
android:textColor="#383838"
android:textSize="14sp"
android:textStyle="bold"
android:maxLength="15"
android:typeface="serif" />
I would like to make an assumption that it's impossible to do that in a simple and elegant way. The problem is that you input type is InputType.TYPE_CLASS_TEXT and it cannot be changed to InputType.TYPE_CLASS_NUMBER because you need to input letters as well.
The problem is that input method checks the type of input and gives you the appropriate keyboard with numbers or alphabet depending on the type of the field input type. If you ask input method to give you number keyboard and you have your EditText in focus, you cannot force the input method to switch to alphabet keyboard in your code. I may be wrong but this is what I think.
The question is whether you can ask any third party input method to give you different keyboard while editing text - I think you cannot do this in your code. Input method will give you numbers or alphabet depending on your EditText but you cannot switch them dynamically because input method is not aware of your design issues. The only way you can do this is to make your own input method that allows you to switch numeric and alphabet keyboards dynamically.

How can I define my own InputFilter and allow for only certain types (see post) of input?

Let's say I have an EditText and I want to restrict it to 0-9 and A-F (inclusive), for hex input. Is there a way I can do that? I tried looking at InputFilters and I'm not sure that's the right way. Has anyone achieved this?
Set the input type to number and digits to "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
In an xml file it would look like this:
<EditText
android:id="#+id/hexedit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
android:inputType="number"
/>
You can experiment with different inputTypes to see which soft keyboard layout they bring up.

How To Validate an EditText to handle numbers only in Android?

How can I validate a text view in android to handle positive integer numbers?
I don't want it to accept any character or signs etc...
Have you taken a look at the EditText's inputType attribute? You can set a whole bunch of different input types that the EditText should limit the user input to.
From the sounds of it, you're probably looking for something like:
<EditText
....
android:inputType="number"
... />
You can use regular expressions. See:
http://developer.android.com/reference/java/util/regex/Pattern.html
Your pattern could look like ^[0-9]{1,10}$
which means that the entered value can only consist of digits (minimum 1, maximum 10)
IMO best way is use inputType in xml
<EditText
...
android:inputType="phone" />
You have to remember that "+" is also part of the phone number.
Use the code in your Edittext XML to restrict any range of values
android:digits="0123456789"
You can use from XML
<EditText
...
android:inputType="phone" />
or programmatically
EditText editText = (EditText) findViewById(R.id.yourId);
editText.setInputType(InputType.TYPE_CLASS_NUMBER);

Categories

Resources