Right now it's showing English when click on the edit text. How can I change the keyboard to Arabic?
I tried installing Arabic keyboard from Google Play, but it is not working in my app.
You cannot set a keyboard for an EditText. The keyboard (or IME) can only be set manually by the user. All you can do is open the dialog from where the user can choose the keyboard. Even for that, the keyboard needs to be enabled in the Language and Input settings
private void showInputMethodPicker() {
InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
if (imeManager != null) {
imeManager.showInputMethodPicker();
} else {
Toast.makeText(this, R.string.not_possible_im_picker, Toast.LENGTH_LONG).show();
}
}
Related
I'm very new to android programming and working on an existing app. The app has a PIN entry with 4 digits. The problem I face, is that the keyboard is not showing every time when the PIN entry mask shows up, sometimes the keyboard is showing and somethimes not. In the app are 4 cases, when the PIN entry is showed: after login, when the app is opened and a user is logged in, to enter the profile settings and to change the PIN. The behaviour is really strange, it isn't like the keyboard gets toggled, so one time it shows and the next time it doesn't, it appears random.
This is the part which should show the keyboard:
public void showSoftInput() {
if (mEditText != null) {
mEditText.requestFocus();
InputMethodManager imm = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
}
}
What you can do is give a focus to your pin edittext, something else is taking the focus, may be because of that keyboard is not coming up.
try requestfocus to give focus to your PIN edittext
Programatically
edittext.requestFocus();
in the xml if you want
<EditText...>
<requestFocus />
</EditText>
Many questions refer to a keyboard service rearing it's head at the wrong time, or how to substitute a view specific keyboard. I have no problem doing this. This problem is different in that the keyboard service pops up on top of a custom keyboard that was working fine until a long press to make a selection. At that point the default keyboard appears. I want to stop this.
As further clarification, it is not the long press that opens the system keyboard. It is action of making a selection. For example: A long press at the end of input does not select anything, but does pop up the "cut copy select all share..." dialog. When you click on "Select All" then the system keyboard opens.
I think the misleading suggestion of a link to a solution to this problem should be removed.
I use the following to install a special keyboard under an EditText:
MA_expression.setOnClickListener { view ->
mKeyboardView.visibility = View.VISIBLE
mKeyboardView.isEnabled = true
if (view != null) {
val imm = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
}
This works as expected:
Now the goal is to use "45" as the argument to a function, so the range of text that is to become the argument is selected (simple here, but it could just as well be embedded in a more complicated expression):
Now the problem is evident -- the standard keyboard service has popped up. It can be dismissed with the done button, the selection remains, my keyboard remains, the FUNa keyboard is selected and the function to apply is picked.
The result is correct, it is only the intervening system keyboard that must be told it is not wanted.
How is that done?
dismiss the android key board on the focus listener
view.setOnFocusChangeListener
view.setOnFocusChangeListener(new OnFocusChangeListener() {
#Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
val imm = getSystemService(Activity.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(view.windowToken, 0)
}
}
});
I am using a custom in-app keyboard, so I need to disable the system keyboard. I can do that with
editText.setShowSoftInputOnFocus(false);
for Android API 21+. But to do the same thing down to API 11, I am doing
editText.setTextIsSelectable(true);
Sometimes I want to show the system keyboard again after disabling it with setTextIsSelectable. But I can't figure out how. Doing the following does show the system keyboard, but if the user hides the keyboard and then clicks the EditText again, the keyboard still won't show.
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, 0);
I guess I could do editText.setOnFocusChangeListener and then manually show or hide the system keyboard, but I would prefer to undo whatever setTextIsSelectable did. The following also does not work:
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.setLongClickable(true);
How do I do it?
Related question
Short answer
Doing the following will reverse the effects of setTextIsSelectable(true) and allow the keyboard to show again when the EditText receives focus.
editText.setTextIsSelectable(false);
editText.setFocusable(true);
editText.setFocusableInTouchMode(true);
editText.setClickable(true);
editText.setLongClickable(true);
editText.setMovementMethod(ArrowKeyMovementMethod.getInstance());
editText.setText(editText.getText(), TextView.BufferType.SPANNABLE);
Explanation
The thing that prevents the keyboard from showing is isTextSelectable() being true. You can see that here (thanks to #adneal).
The source code for setTextIsSelectable is
public void setTextIsSelectable(boolean selectable) {
if (!selectable && mEditor == null) return; // false is default value with no edit data
createEditorIfNeeded();
if (mEditor.mTextIsSelectable == selectable) return;
mEditor.mTextIsSelectable = selectable;
setFocusableInTouchMode(selectable);
setFocusable(selectable);
setClickable(selectable);
setLongClickable(selectable);
// mInputType should already be EditorInfo.TYPE_NULL and mInput should be null
setMovementMethod(selectable ? ArrowKeyMovementMethod.getInstance() : null);
setText(mText, selectable ? BufferType.SPANNABLE : BufferType.NORMAL);
// Called by setText above, but safer in case of future code changes
mEditor.prepareCursorControllers();
}
Thus, the code in the short answer section above first sets mTextIsSelectable to false with setTextIsSelectable(false) and then undoes all of the other side effects one-by-one.
I have an EditText with the ImeOptions set to EditorInfo.IME_ACTION_NEXT. So the "Next" button is displayed on the keyboard when the field is focused.
I want the button to change for "Done" WHILE the user is typing (for some reasons).
So I have a TextWatcher and I try to change the ImeOptions to EditorInfo.IME_ACTION_DONE on "afterTextChanged" but the key on the keyboard doesn't change.
I tried to hide the keyboard, change the ImeOptions and show the keyboard again but it doesn't work (this solution works for iOS).
Does someone know how to do that?
I tried this and it works, the problem is that you can sometime see when the keyboard appears and disappears.
#Override
public void afterTextChanged(Editable s) {
if (/*condition*/) {
// Change the IME of the current focused EditText
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
// Hide the keyboard
hideKeyboard(activity);
// Restart the input on the current focused EditText
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(editText);
// Show the keyboard
showKeyboard(activity);
}
}
You can try something like that:
if (your condition) {
youreditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
hideKeyboard(activity);
InputMethodManager input= (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
input.restartInput(youreditText);
showKeyboard(youractivity);
}
From the answers above:
// Restart the input on the current focused EditText
InputMethodManager imm = (InputMethodManager) activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.restartInput(editText);
Only restarting the input does the trick. Otherwise, presumeably keyboard flickering is to be expected. Input restart also doesn't clear the field's contents i.e. doesn't lead to data loss, which is the desired behavior.
I am developing one small application in android which consist of an Edit Text & Button. Button will be visible only after edit text is not blank.Since I am having LG Optimums Android device, Whenever i click on Edit Text since it it LG device, LG Key Board will appear but i don't want that Key Board i want Android Key Board to use. I Also know that i can go into Setting=>Language & Key Board & i can change that Key Board. But i don't want to use that i want it should be done only through coding.
Thanx for any Help.....
It's not possible to change the keyboard settings for the user programmatically. The only thing you can do is advise the user to change it and help it to do so. For instance, this will show a dialog for them to change keyboard:
private void showInputMethodPicker() {
InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
if (imeManager != null) {
imeManager.showInputMethodPicker();
} else {
Toast.makeText(this, R.string.not_possible_im_picker, Toast.LENGTH_LONG).show();
}
}
As far as I've seen, and from an Android employee here, it is simply not possible to change the IME programatically - it is completely dependent on the end-user to choose their preferred IME.
Like Paul said you cannot change the IME; however, you can disable the android softkeyboard by hiding it
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
then create a view that resembles an android softkeyboard. Check this out.
Change the keyboard from your app on Button Click :
Button keyboard = (Button) findViewById(R.id.keyboardChange);
keyboard.setOnClickListener(new View.OnClickListener() {
public void onClick(View view)
{ InputMethodManager imeManager = (InputMethodManager) getApplicationContext().getSystemService(INPUT_METHOD_SERVICE);
imeManager.showInputMethodPicker();
}
});