Android: Change "Done" button text on keyboard - android

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;
}
});

Related

What is the keycode for search/next/send button

does anyone know what keycode I have to press for this Send/Search/Next button?
I'm trying to send a chat message and can't find a solution to this one.
Already tried keycode: 66 and 84.
keyboard view
For adding action on click of send/done button of soft keyboard, Need to add setOnEditorActionListener to edittext.
EditText code in xml :
<EditText
android:id="#+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:imeOptions="actionSend"
android:singleLine="true"/>
In Java class:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEND) {
String text = editText.getText().toString();
Log.e(TAG,"text-----"+text);
return true;
}
return false;
}
});
You can add any imeOptions to edittext according to your requirement.
For more info related to EditerInfo check official doc.

How to display "search" as text instead of Serach icon on android soft keyboard

How to replace the search icon with text "Search" on soft keyboard.
<EditText
android:imeOptions="actionSearch" />
Instead of using imeOptions use the following :-
<EditText android:imeOptions="actionSearch"
android:inputType="text"/>
For handling click listener do as follows :
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH) {
performSearch();
return true;
}
return false;
} });
Answer taken from this stackoverflow question.
Try to set
android:imeActionLabel in XML or
in java code with .setImeActionLabel()
editText.setImeActionLabel(getString(R.string.xxx), EditorInfo.IME_ACTION_SEARCH);

android:imeOptions not go to the exact next EditText

I have 2 EditText with id (et_1 and et_2) in a layout, and I set
for et_1
android:imeOptions="actionNext",
android:nextFocusForward="#+id/et_2"
when et_1 gets focus and the the software keyboard shows "Next", and when I click "Next", the focus doesn't go to et_2, but to another EditText in another fragment layout. Why is it this way?
How to make the focus go to et_2?
Thanks.
Try changing,
android:nextFocusForward="#+id/et_2"
to
android:nextFocusDown="#+id/et_2"
I hope it helps!
I had the same problem in one of my apps. What I did instead was have a listener in my activity for when "Next" was pressed and then just manually changed the focus. Like this:
final EditText et_1 = (EditText)findViewById(R.id.et_1);
final EditText et_2 = (EditText)findViewById(R.id.et_2);
// listen on the et_1 EditText
et_1.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if(actionId == EditorInfo.IME_ACTION_NEXT) { // "Next was selected"
et_2.requestFocus(); // focus on et_2
}
return true;
}
});
I realised referencing does not hide the keyboard
android:nextFocusDown="#+id/et_2"
To Hide the Keyboard add actionDone
<EditText
android:id="#+id/editTextEnterAmount"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Amount"
android:imeOptions="actionDone"
/>

Android disable Enter key in soft keyboard

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.

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