Android disable Enter key in soft keyboard - android

Can anyone tell me how to disable and enable the Enter key in the soft keyboard?

just go to your xml and put this attribute in EditText
android:singleLine="true"
and your enter key will be gone

Attach OnEditorActionListener to your text field and return true from its onEditorAction method, when actionId is equal to IME_ACTION_DONE. This will prevent soft keyboard from hiding:
EditText txtEdit = (EditText) findViewById(R.id.txtEdit);
txtEdit.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
// your additional processing...
return true;
} else {
return false;
}
}
});
Refer this LINK.

Try this, together imeOptions = actionDone
<EditText
android:id="#+id/edittext_done"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:imeOptions="actionDone"
android:maxLines="1"/>

In the EditText's layout put something like this:
android:digits="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ,"
You can also enumerate the rest of the symbols that you would like to be able to enter there, but not the enter key.

I know this question is quite old but an easy way of disabling the enter key is to set android:maxLines="1" in your EditText.

Related

onEditor action not working when trying to respond to the tick on the android numeric soft keyboard

I have an EditText in my app with an input type of number:
<EditText
android:id="#+id/answerText"
style="#style/GeneralTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/question"
android:layout_toRightOf="#id/equals"
android:inputType="number"
android:paddingTop="#dimen/activity_vertical_margin"
android:maxLength="3"
android:visibility="invisible"
tools:text="ans"/>
So when the EditText has focus the numeric keyboard is displayed. I am trying to repond to the user pressing the tick button after supplying a value in the EditText but I can't get it to work.
I've tried the following code which I've put inside the onCreate method but it isn't working:
answerGivenText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE){
return true;
}
return false;
}
});
Can anyone help please?
I think you should add the
android:imeOptions="actionDone"
attribute to your edittext.
That code is exactly what you need, but you are not doing anything inside it, you're just intercepting the click and returning true, indicating that you handled it to other listeners on the stack.
You would do whatever it is you want to do when the user clicks the tick in the
if (actionId == EditorInfo.IME_ACTION_DONE)
section. And turn on the DONE action in your layout. What exactly are you trying to achieve?

Android: Change "Done" button text on keyboard

I am new to Android development. Is it possible to change "Done" button's text on keyboard? If yes, how to do that?
EditText input = new EditText(context);
input.setImeOptions(EditorInfo.IME_ACTION_DONE);
input.setImeActionLabel("My Text", EditorInfo.IME_ACTION_DONE);
Alternatively you can do it in the XML
android:imeActionLabel="My Text"
you can set ImeOptions for textview in xml. their are many as per
this
Link for imeOptions
for example various imeOptions..
actionNone IME_ACTION_NONE.
actionGo IME_ACTION_GO.
actionSearch IME_ACTION_SEARCH.
actionSend IME_ACTION_SEND.
actionNext IME_ACTION_NEXT.
android:imeOptions="actionDone"
use like this:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionGo"
/>
and call this function to use action:
mInstrunctionEditTxt
.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
// do what action you want
}
return false;
}
});

Android keyboard next button issue on EditText

I am facing an issue, I have username & password fields on activity, now when I click on username keyboard appears but no next button on it and I cannot move to next Edittext control through keyboard in this case, keyboard displays enter button in it as attached in screenshot which increases its height,
Can anyone guide me what is the solution to this problem (to display next button on edittext)?
My Code
txtUserid = (EditText)findViewById(R.id.txtUserID);
txtUserPasword = (EditText)findViewById(R.id.txtPassword);
txtUserid.setNextFocusDownId(R.id.txtPassword);
txtUserPasword.setNextFocusDownId(R.id.btnLogin);
Add android:singleLine="true" android:nextFocusDown="#+id/textView2" on your xml.
Will show Next key and also focus to the next field.
In your layout, just set the XML attributes android:imeOptions="actionNext" for your first three text boxes and android:imeOptions="actionDone" for the last one.
More Examples
add this lines below your lines of code you provided:
txtUserid.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
// If the event is a key-down event on the "enter" button
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
txtUserid.clearFocus();
txtUserPasword.requestFocus();
return true;
}
return false;
}
});
txtUserPasword.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
// Perform action on Enter key press
// check for username - password correctness here
return true;
}
return false;
}
});
Another best solution would be:
android:singleLine="true"
android:imeOptions="actionNext"
If your EditText is supposed to have only 1 line, add the attribute android:singleLine="true" on your XML, that will remove the Enter key and replace it with Next / Done button.
add your xml layout ,
in suppose u want 4 edittext in row so first three editext u set below,
android:imeOptions="actionNext"
and last one editext u set
android:imeOptions="actionDone"
u add line so add,Use
android:singleLine="true"
You need to take care of few things:
Add android:singleLine="true".
Add android:nextFocusDown="#+id/tv2" on your XML.
Don't add android:imeOptions="actionNext", otherwise it will override above two attributes.
use this attribute:
android:inputType="textPersonName"
Add
android:inputType="text"
line in your edittext tag. and your problem will be resolved.
Just add android:singleLine="true" to the EditText tag in the layout XML..
Just add android:singleLine="true" you don't need that code for that
android:singleLine="true" is deprecated
use
android:maxLines="1"
android:inputType="text"
instead

getting numeric keyboard default

How can I change android's default keyboard?
I want numeric keyboard to be shown first and then on clicking ABC in the numeric keyboard, I want to show alphabets keyboard.
Is that possible to implement?
Thanks in advance.
Assuming you're using a TextView for your text input, you simply need to set the inputMethod property.
http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputMethod
As I said in this question, I didn't find any answer to that except if you wrote your own keyboard
You can do that with the word "phone" in inputype property of your EDITTEXT
Use InputType="number" in your edittext
Just implement IME option on your numeric keyboard and once clicked change input type programmatically like this:
EditText editText= (EditText) mView.findViewById(R.id.et_awesome);
editText.setOnEditorActionListener(new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(EditText v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_GO) {
editText.setInputType(InputType.TYPE_CLASS_TEXT);
return true;
}
return false;
}
});
EditText on XML:
<EditText
...
android:imeOptions="actionGo"
android:imeActionLabel="ABC"
android:imeActionId="666"
android:inputType="number"/>

Done is not working in softKeyboard in Autocomplete TextView in android

I have One AutocompleTextView and I want to make the virtual keyboard disappear when he hits "DONE" at the AutocompleTextView. So far, the buttons "NEXT"/"DONE" do nothing at all. Any ideas?
Add this Property to your AutoCompleteTextView in xml:
android:imeOptions="actionDone"
The following works for all the Views which support imeOptions; for instance EditText, TextView, AutocompleteTextView, etc.
In your xml:
<autocompleteTextView
inputType = "text"
imeOptions = "actionDone"
/>
In Java:
autocomplete = (AutoCompleteTextView) issueDetailView.findViewById(R.id.yourId);
autocomplete.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId== EditorInfo.IME_ACTION_DONE) {
//do Whatever you Want to do
}
return true;
}
});
Just add the following on yours XML layout file:
android:imeOptions="actionDone"
android:singleLine="true"
Check android:imeOptions attribute.
In my case android:imeOptions only works if i set android:inputType which is
android:inputType="textAutoComplete" android:imeOptions="actionDone"

Categories

Resources