Android software keyboard switch between numeric and alphabetic programmatically - android

I have an EditText with inputMode = text. By default software keyboard is shown as alphabetical and user have to switch it to numeric by pressing specific key (like "123").
Having text inputMode is it possible to show numeric keyboard by default instead of alphabetic?
I need both alphabetic and numeric. But numeric is used more often then alphabetic so i search for way to switch mode programmatically.

I find the answer a day, finally I found this and its work.
android:inputType="textVisiblePassword"
source

Just set it with the normal setter:
EditText editText = (EditText) findViewById(R.id.edittext);
editText.setInputType(InputType.TYPE_CLASS_NUMBER);
// or
editText.setInputType(InputType.TYPE_CLASS_TEXT);

you can achieve it by setting the below attribute to EditText on xml has follows android:inputType="number"

Related

Edittext imeOptions actionDone not working with digits attribute?

I have an Editext . It contains attribute digits and imeOptions (actionDone) together.
<android.support.v7.widget.AppCompatEditText
android:id="#+id/edit_text_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="1234567890abcdefghijklmnopqrstuvwxyz....."
android:hint="#string/item_name"
android:imeOptions="actionDone"
android:maxLines="1" />
The actionDone (Done button in Softkeyword) not found while using digit && imeOptions attributes together . We can only find enter button which doesn't make any focus change. I have tried it by skipping digit attribute , then imeOptions working correctly.
Thanks in advance
Just add singleLine="true" to your edittext
android:singleLine = "true"
Use setRawInputType() on your EditText View
view.setRawInputType(view.getInputType() & ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE)
It is important to call setRawInputType() and not setInputType(), since the latter will set the keylistener based on the inputmethod and your android:digits attribute will be discarded. setRawInputType() will only change the inputmethod and it won't touch the KeyListener, furthermore & ~EditorInfo.TYPE_TEXT_FLAG_MULTI_LINE will disable the multi line mode, so no return key will be visible, instead your chosen imeOption should be visible.
Basically, there is a different behavior of singleLine and maxLines.
My testing with "android:digits" seems to cause problems in edittext fields and when setting imeOptions to android:imeOptions="actionDone" I could not get the "Done" button to appear on the keyboard.
Once I used
android:inputType="text"
without digits setting, the keyboard then presented "Done" (or a tick depending on your device's keyboard), and I could then capture the key stroke using:
editextField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
int result = actionId & EditorInfo.IME_MASK_ACTION;
switch(result) {
case EditorInfo.IME_ACTION_DONE:
// put your code here.
break;
}
return false;
}
});
Hi you can programmatically set :
EditText edit = view.findViewById(R.id.memo_edit_text);
edit.setRawInputType(InputType.TYPE_CLASS_TEXT);
edit.setImeActionLabel("DONE", EditorInfo.IME_ACTION_DONE);
edit.setImeOptions(EditorInfo.IME_ACTION_DONE);
On the EditText that you want to associate with an IME Action
It works for textMultiLine and with any digits, just chose your action
credits : https://stackoverflow.com/a/52503760/11858207
In Kotlin you can also set
isSingleLine = true

Android EditText with inputType and Enter button

I need make multiline EditText input with inputType="textCapWords|textNoSuggestions" but leave Enter(new line) button in keyboard.
Problem i have is that when i put inputType attribute on edittext it changes enter button to next button.
so, is there way to have EditText with inputType attribute set and working enter button?
thanks for suggestions
It looks like when I add inputType attribute it force EditText into singleline
I just added textMultiLine into inputType.
so it is inputType="textCapWords|textNoSuggestions|textMultiLine" and it works
You should check this XML property : android:imeOptions and its actionDone value

Android How to show numeric softkeyboard with EditText of InputType="text"

I need allow to user input numeric information in a EditText, but the output needs to be formatted like "##.###,##" (# in [0..9]). The formatting I was made in a TextWatcher... this is good, the TextWatcher does the job... bute, when user selects the EditText, as it marked as text, the AlphaKeyboard is shown, if I select the EditText as numeric the keyboard I need is shown and the TextWatcher stop working.
put the following in your xml at the required edittext
<EditText android:inputType="number" ... />
refer to
How do I show the number keyboard on an EditText in android?
You need to change edittext entry like this.
<EditText android:inputType="phone" android:numeric="decimal"></EditText>
Use this code to show soft keypad.
InputMethodManager imm = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInputFromInputMethod(v.getApplicationWindowToken(), 1);
As you are doing formatting in TextWatcher (##,####....) i.e. you are adding "," in EditText and you have made the EditText as numeric. If its numeric then "," char is invalid. Thus its not allowing TextWatcher to update the formatted text that contains ',".
You have 3 options to deal with this problem :
Make the EditText as normal instead of numeric. In TextWatcher look out for any other invalid chars other than 0-9. You can show IME for Mumber keypad when the focus is on the EditText.
Use Mask for EditText.
Let it be numeric. Trap FocusGain & FocusLost for the EditText. In focusGain, remove the formatting & set the inputType to Numeric. & In focusLost, first make the input type to Normal and then update the entered value to formmated value. You can set the input type to normal at runtime using setInputType(InputType.TYPE_TEXT_VARIATION_NORMAL); & for numeric use : setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
I believe 1st option will be best to handle and manage out.

android EditText inputType for StreetNumber field

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)

Android virtual keyboard turn on caps lock

I have an edit text field. When the user clicks on it by default it shows small letters on the virtual keyboard.
I want by default to display first letter caps and rest of them small on the keyboard.
How can this be done?
android:capitalize is deprecated. So please use: android:inputType
android:inputType="textCapSentences"
Try adding android:capitalize="sentences" to the definition of the EditText in your Layout file. This should capitalize the first character of the sentence. If you want to begin each word with a capital letter use words.
More about this can be found in the API.
In order to captialize every character of EditText
use these property.
android:capitalize="characters"
I used below attribute with textCapCharacters value in my EditText to turn on caps lock on the virtual keypad and it worked.
android:inputType="textCapCharacters"
To capitalize all characters of Keyboard use this in your edittext in xml:
android:inputType="textCapCharacters"
To capitalize of the first character of every sentence use this :
android:inputType="textCapSentences"

Categories

Resources