I use EditText to do input actions, and set android:imeOptions="actionSend" to the widget, so that the soft keyboard can have a send button, but when I click send, the soft keyboard will disappeared, however, it's not friendly to users since user must click EditText again to use the soft keyboard, all I want is to keep the soft keyboard, does any one know how to achieve it?
Here is a piece of my layout codeļ¼
<EditText
android:id="#+id/input_area"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toLeftOf="#id/emo_btn"
android:inputType="textAutoCorrect"
android:singleLine="true"
android:imeOptions="actionSend"/>
you are using setOnEditorActionListener or setOnKeyListener ? on both case try your return statement with true
Related
Between the Activity tags in my AndroidManifest.xml I have :
android:windowSoftInputMode = "stateVisible"
So when my activity starts the soft keyboard comes up:
Is there not something I can add to make the phone input keyboard come up instead? Or how would I do it? Thanks.
EDIT
For the sake of clarity to this question I'm adding this 'edit'.
First of all, thanks for all the answers below.
However, my objective is to have no Edittext Visible on the screen, at first. The Phone Input soft keyboard comes up as soon as the activity starts and when the user starts
to type then the Edittext will become visible, with the text being typed.
I tried making the Edittext invisible, and then make it visible when user starts typing, but the problem is an invisible edittext can't have the focus,
So, android:inputType="number" was having no effect. And neither was: edittext.requestFocus(); Because the edittext was invisible.
What I ended up doing eventually was something very simple, setting width and height to 0dp in my xml like :
android:id="#+id/etPhoneNumber"
android:layout_width="0dp"
android:layout_height="0dp"
android:inputType="number" />
That way, the edittext can get focus with
edittext.requestFocus();
as soon as the activity is created, and inputType = "number" is recognised.
The next thing I'll do is increase the size of the edittext as soon as a key is hit on the soft keyboard, so users can see it.
I'll put all this in as an answer so it might be helpful to other users. +1 for the help!
Assuming that you have an EditText in the Activity which you show once your app is started, you can add below XML Attribute to your EditText.
android:inputType="phone"
Check developer docs for other input types in case if you need.
You can add
android:inputType="phone"
or
android:inputType="number"
to your View in your XML layout.
You should have some View in your code where you can give input like EditText or AutoCompleteTextView for changing the type of the keypad.
For example -
<EditText
android:layout_width="match_parent"
android:layout_height="50dp"
android:inputType="phone"
/>
In manifest file set the property in activity,
android:windowSoftInputMode="stateAlwaysVisible"
and then in your xml where your EditText set the property,
android:inputType="number"
first of all take an EditText in your xml
<EditText
android:id="#+id/etPhoneNumber"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="number" />
use this piece of code in the onCreate method of your activity !
EditText etPhoneNumber = (EditText) findViewById(R.id.etPhoneNumber);
etPhoneNumber.requestFocus();
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
This works for me very well ! Hope it works for you too !
Let me know if this works ! :)
The objective is to have no Edittext Visible on the screen, at first.
The Phone Input soft keyboard comes up as soon as the activity starts and when the user starts
to type then the Edittext will become visible, with the text being typed.
I tried making the Edittext invisible, and then make it visible when user starts typing, but the problem is an invisible edittext can't have the focus,
So, android:inputType="number" was having no effect. And neither was: edittext.requestFocus(); Because the edittext was invisible.
What I ended up doing eventually was something very simple, setting width and height to 0dp in my xml like :
android:id="#+id/etPhoneNumber"
android:layout_width="0dp"
android:layout_height="0dp"
android:inputType="number" />
That way, the edittext can get focus with
edittext.requestFocus();
as soon as the activity is created, and inputType = "number" is recognised.
The next thing to do now is increase the size of the edittext as soon as a key is hit on the soft keyboard, so users can see it.
I set imeoptions="actionDone" for my EditText in xml and everything works fine on a Medion Lifetab or Nexus 4 (on press "Enter" the softkeyboard disappears).
But I need this to work on a Honeywell Dolphin e70. On this device if I press "Enter" the next EditText gets focus. I already tried to set singleline true but didnt change the behavior.
This is the EditText I use:
<EditText
android:id="#+id/id1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".55"
android:imeOptions="actionDone"
android:inputType="textCapSentences"
android:selectAllOnFocus="true"
android:textSize="#dimen/dimen1" />
Like I said, on other devices it works like intended.. Anyone got an idea for a workaround or where I can start handling this? I definetly dont want to set a keylistener to EVERY damn EditText is the application, that would totaly be an overkill..
thanks
You can see Close/hide the Android Soft Keyboard to hide the keyboard and Android Use Done button on Keyboard to click button to catch the dome button action.
Well this is making me a bit crazy.
I've got 2 Edit Text fields and a button. I want the soft keyboard to display when the 1st Edit Text gets focus. I want the soft keyboard to show the "Next" key so when its pressed the cursor jumps to the second Edit Text field.
When the second Edit Text field gets the cursor, I still want the soft keyboard to show "Next". Pressing "Next" now will dismiss the soft keyboard and make focus go to the button.
Here's my code:
EditText editText1 = (EditText) findViewById(R.id.some_text_field);
EditText editText2 = (EditText) findViewById(R.id.some_other_text_field);
editText1.setInputType(EditorInfo.some constant);
editText1.setFocusable(true);
editText1.setFocusableInTouchMode(true);
if (editText1.requestFocus()){
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
if (imm != null){
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,0);
}
}
editText1.setImeOptions(EditorInfo.IME_ACTION_NEXT);
editText1.setNextFocusDownId(R.id.some_other_text_field);
editText2.setInputType(EditorInfo.some other constant);
editText2.setFocusable(true);
editText2.setFocusableInTouchMode(true);
editText2.setImeOptions(EditorInfo.IME_ACTION_DONE);
Seems pretty straightforward.
Thing is, the first time this runs (after app install) editText1 gets focus and the soft keyboard displays BUT there is no "Next" key - instead it displays "Done". Pressing "Done" moves you to editText2 (like you want) and changes "Done" to "Next. Hitting "Next" now leaves focus on editText2 and dismisses the soft keyboard.
IF you touch editText1 now, the soft keyboard displays and the "Next" key appears like its supposed to.
What can I do to get the proper behavior (editText1 gets focus, "Next" displays) to happen on the first run of this Activity?
I thought editText1.setImeOptions(EditorInfo.IME_ACTION_NEXT); was supposed to force the "Next" key to display. What am i missing?
Have you tried doing the same from layout file. I did it in layout file and is working. Following is my working code for login edittexts
<EditText
android:id="#+id/et_sign_in_with_email_email"
style="#style/SignInEditText"
android:layout_below="#id/rl_titlebar_signin"
android:layout_marginTop="16dp"
android:hint="#string/hint_email"
android:imeOptions="actionNext"
android:inputType="textEmailAddress" >
</EditText>
<EditText
android:id="#+id/et_sign_in_with_email_pwd"
style="#style/SignInEditText"
android:layout_below="#+id/et_sign_in_with_email_email"
android:layout_marginTop="20dp"
android:hint="#string/hint_pwd"
android:imeOptions="actionDone"
android:inputType="textPassword" />
to navigate the focus to the next edit field add
android:imeOptions="flagNavigateNext"
and for dismissing the softkey with done click add
android:imeOptions="actionDone"
i have several EditText in my App. If you hit the Enter Key you can tab to the next EditText without a problem but i would like to change the Enter Key so that this button doesn't shows the Enter Simbol but instead it shows "Next" or "Done". i tried many things but without any results. Here is the XML code for my EditText:
<EditText
android:id="#+id/et_nt_name"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:imeOptions="actionNext|flagNoEnterAction"
android:imeActionLabel="Next"
android:singleLine="true"
android:inputType="textShortMessage"
/>
it is the case that some soft keyboards actually change the default text on the enter key by design, so it may not be your fault that it's not showing what you want it to show. the functionality should be the what you programmed it to do, though.
i recommend you switch to the default keyboard (long press on any edit text, then select input method) to verify that it's showing the correct text, and don't care about the what the other soft keyboards look like .
if your phone didn't come with the default soft keyboard, the Android emulator is your best friend.
Add this to your EditText,
android:imeOptions="actionDone"
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_weight="1"
android:id="#+id/name" android:singleLine="true"
android:maxLength="12" android:capitalize="none" android:inputType="text" />
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="#+id/search_button"
android:text="Search" />
I have this at the top of my application. When the application starts, the EditText is orange highlighted and has a cursor in it; when the EditText is tapped, the soft keyboard pops up. The user uses it to type into the EditText.
However, when they click the Button, my onClick method fires and does everything it's supposed to, however the soft keyboard stays on screen and the EditText is still highlighted with its cursor.
I also have, at the top of the Button onclick:
findViewById(R.id.name).clearFocus();
In spite of this, the EditText does not seem to clear its focus. How do I make the button actually act as if it is submitting the form?
Also, I do not transition to a different Activity on the click of the Button. I suppose that is the typical case, and probably the reason why they don't bother hiding the keyboard. However I want to keep the search box and button at the top of the screen, so I just dynamically fill and add views to the screen when the Button is pressed.
How can I achieve my desired behavior?
You can hide the keyboard by calling this.
InputMethodManager imm = (InputMethodManager) getSystemService(
INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(getWindowToken(), 0);