How can I get a "done" button in softkeyboard? - android

how can I have a "done" button in my softkeyboard (Samsung Galaxy 10.1, Android 3.1) when writing in an EditText?
Using
<EditText
android:id="#+id/comment"
android:layout_width="772dp"
android:layout_height="200dp"/>
I get
If possible, I'd also like to remove this "attachment" button.
Anybody can help?
EDIT
I managed to get a "Done" button using
android:inputType="textImeMultiLine",
but the "return" button disappeared...
How can I have both? (I asked this new question here).

add this to your EditText xml:
android:imeOptions="actionDone"
or, to set it from code:
yourEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
for more, read this

Using my Galaxy S2 phone
For the code below, each EditText will have a Return button that adds a new line:
EditText editText = new EditText(this);
For the code below, each EditText will have a Next button that navigates to the next field and the last one will have Done button that will dismiss the keyboard:
EditText editText = new EditText(this);
editText.setInputType(InputType.TYPE_CLASS_TEXT);
For the code below, no change, each EditText has a Return button:
EditText editText = new EditText(this);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
For the code below, all EditText will have a Done button and all will dismiss the keyboard.
EditText editText = new EditText(this);
editText.setInputType(InputType.TYPE_CLASS_TEXT);
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
For layouts use code below:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="text"
android:imeOptions="actionDone"/>

In my Intel x86 Emulator at least, the "Done" key appears only if you specify the input type: "phone", "number", "text", "textPassword", ... with android:inputType. If you don't specify any or you set "textMultiLine", "Done" does not appear.
android:imeOptions="actionDone"
and
editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
seem useless, since they don't change anything either in the first case (where "Done" appears anyway) or in the in the second case (since "Done" keeps not appearing) !

Add the next code to your EditText in xml
android:imeOptions="actionDone"
android:imeActionLabel="#string/done"
android:singleLine="true"
The android:inputType="text" field is optional

Use TextView.setImeOptions and pass it actionDone.

Related

how is the correct desing pattern to hide/show EditText in Android?

I have developed an Health App in Android, and i have an Activity where the first question is a Yes/No answer (i make with 2 checkboxes), depending the Yes/No answer the activity shows diferents EditText to complete. I really know how to hide EditText and how to show when the user click the checkboxes, but the question is if exist a correct design pattern to do this? i read the Material Desing web , but i didnt find nothing about this. It is correct way to do? Or i must enable/disable the EditTexts.
If you only need to set a few EditText's, your way is right.
OPTION A
Imagine that "foo()" returns which is the EditText that you have to show.
In your layout:
<EditText
android:id="#+id/edit1"
android:visibility="GONE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/edit2"
android:visibility="GONE"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
....
Now, in your code:
...
switch(foo()){
case 1: //You have to show the first EditText
EditText edit1 = (EditText)findViewById(R.id.edit1);
edit1.setVisibility(View.VISIBLE);
break;
case 2: //You have to show the second EditText
EditText edit2 = (EditText)findViewById(R.id.edit2);
edit2.setVisibility(View.VISIBLE);
break;
....
}
OPTION B
Another choice would be adding the EditText programatically, something like:
EditText editText = new EditText(context); // Pass it an Activity or Context
editText.setLayoutParams(new LayoutParams(..., ...)); // Pass two args; must be LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, or an integer pixel value.
myLayout.addView(editText);
In this case, you dont need to add the EditText's in the layout file, you are going to add it dynamically only if you need it!
Generating Edit Text Programatically in android
Hope it helps!

Display smiley button at right bottom on Android keyboard

I need to show smileys button by default when user input in my EditText.
Now keyboard for my EditText looks like:
Look at the right bottom, you will see done button.
In same time in sms app keyboard looks like:
[
At the right bottom displays smiles button.
How do I display smile button in keyboard for my EditText?
Now I have next ExitText layout:
<EditText
... // some layout params
android:inputType="textCapSentences|textAutoCorrect|textAutoComplete"/>
You can try by adding following attributes in your EditText. Missing property in you code is textShortMessage. So you can try by adding same.
android:inputType="textShortMessage|textAutoCorrect|textCapSentences|textMultiLine"
android:imeOptions="actionSend|flagNoEnterAction"
You just have to add imeOption textShortMessage.
<EditText
... // some layout params
android:inputType="textShortMessage|textCapSentences|textAutoCorrect|textAutoComplete"/>

Change "Done" button in Android numeric keyboard

I have an EditText in Android configured for the number keyboard, and I would like the keyboard's button to say "next", while mine is saying "done".
How can I change that?
I already tried:
<com.innovattic.font.FontEditText
style="#style/CadastroTextBoxStyle"
android:hint="CEP"
android:id="#+id/etCEP"
android:inputType="number"
android:singleLine="true"
android.imeOptions="actionNext" />
And also this:
etCEP.setImeActionLabel("Next", KeyEvent.KEYCODE_ENTER);
But it still says done.
What else can I do?
Thanks
As can be seen in Specifying the Input Method Type, you do not need to call TextView.setImeActionLabel(CharSequence, int) and you have to instead just provide a android:imeOptions value such as actionSend or actionNext in XML attributes to change the label accordingly.
This is not working for you because you have mistyped : as . in your attributes. Switching those out should fix your issue in no time.

Show/Hidden Soft Keyboard event in Android

I need to get the Show/Hidden event from the SoftKeyboard in Android.
I did a research, but nothing worked.
I wanted that 'cause we're working with a tablet 5.0'' with low resolution, so when you edit a EditText, the keyboard rise in full screen, and then or you press the "enter or next" key, or you press the back button to hide the keyboard... I need to update some fields with the new value, but I can't use the TextWatcher 'cause have some business logics on what's the right fields to update, and 'cause I just want to update when the user really finish the input.
And the onFocusChanged isn't a option, 'cause we don't want our customers needing to cliking in the next field, and hiding the keyboard to see the new values.
I don't want to override the onTouchEvent too, see if where the user cliked isn't the same field that he is editing.
Sorry for the specific problem and more specific solution that I'm asking for.
And sorry for my bad English :D
Use tree view observer to detect any change in view height and that time you can check whether keyboard state
final View activityRootView = findViewById(R.id.chat_pane_root_view);
activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener()
{
#Override
public void onGlobalLayout()
{
InputMethodManager mgr = (InputMethodManager) mContext.getSystemService(Context.INPUT_METHOD_SERVICE);
if(mgr.isAcceptingText())
{
//keyboard is up
}
}
});
First of all in your declairation of your activity in manifest file declaire like this
<activity android:name="Map" android:windowSoftInputMode="stateHidden">
from this property your keyboard is being hidden,
after this you are declaire the imeOption property in your main.xml file edittext like this
<EditText
android:id="#+id/edttexttitle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:hint="#string/tasktitle"
android:imeOptions="actionNext"
android:inputType="text"
android:textSize="#dimen/font_size_medium"
android:textColor="#color/darkgray1" />
this code is for your first edittext if more then one and if only one edittext then your need to change the imeOption of edittext like
android:imeOptions="actionGo"

Show soft keyboard (numeric) using AlertDialog.Builder

I have an EditText in an AlertDialog, but when it pops up, I have to click on the text box before the keyboard pops up. This EditText is declared in the XML layout as "number", so when the EditText is clicked, a numeric keypad pops up. I want to eliminate this extra tap and have the numeric keypad pop up when the AlertDialog is loaded.
All of the other solutions I found involve using
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
This is NOT an acceptable solution, as this results in the standard keyboard rather than the numeric keyboard popping up. Does anyone have a way to make the numeric keyboard pop up in an AlertDialog, preferably while keeping my layout defined in XML?
AlertDialog dialog = new AlertDialog.Builder(this)
.setTitle("Mark Runs")
.setView(markRunsView)
.setPositiveButton("OK", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
EditText runs = (EditText)markRunsView.findViewById(R.id.runs_marked);
int numRuns = Integer.parseInt(runs.getText().toString());
// ...
})
.setNegativeButton("Cancel", null)
.show();
Edit: I want to be perfectly clear that my layout already has:
android:inputType="number"
android:numeric="integer"
I also tried this:
//...
.setNegativeButton("Cancel", null)
.create();
EditText runs = (EditText)markRunsView.findViewById(R.id.runs_marked);
runs.setInputType(InputType.TYPE_CLASS_NUMBER);
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
dialog.show();
but that also did not work. With the setSoftInputMode line, I still get the full keyboard when the AlertDialog loads; without it, I still get nothing. In either case, tapping on the text box will bring up the numeric keypad.
Edit Again:
This is the XML for the EditText
<EditText
android:id="#+id/runs_marked"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="4dip"
android:inputType="number"
android:numeric="integer">
<requestFocus/>
</EditText>
Coming a bit late, but today I had this same problem. This is how I solved it:
Call the keyboard when the Dialog opens just like you did:
dialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
Now, into the Dialog I'm assuming you have a EditText field that accepts only numbers. Just request focus on that field and the standard keybord will automatically transform into the numeric keyboard:
final EditText valueView = (EditText) dialogView.findViewById(R.id.editText);
valueView.requestFocus();
Now you just have to remember to dismiss the keyboard once you're done with the Dialog. Just put this in the positive/negative/neutral button click listener:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(valueView.getWindowToken(), 0);
Just try to set the InputType by using setInputType().
EditText runs = (EditText)markRunsView.findViewById(R.id.runs_marked);
runs.setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL);
I think that you should keep on using the setSoftInputMethod hack but also provide hints to android that you want a numeric input.
Using xml layout attributes
For this, you can use several xml attributes to your EditText xml definition (see android:inputType for available options)
Examples:
<EditText android:inputType="phone" ...
<EditText android:inputType="number" ...
<EditText android:inputType="numberSigned" ...
<EditText android:inputType="numberDecimal" ...
You can also both hint android to show digital keyboard and restrict input to acceptable characters with android:numeric
Examples:
<EditText android:numeric="integer" ...
<EditText android:numeric="signed" ...
<EditText android:numeric="decimal" ...
Programatically
Use EditText.setRawInputType(int) with constants such as TYPE_CLASS_NUMBER you will find in android:inputType
or TextView.setKeyListener(new NumberKeyListener())
EDIT
AlertDialog focus by default on the positive button. It seems that it is what is causing trouble here. You may look at this similar question and its answer.
Try to specify in layout xml for your edit box:
<EditText ...>
<requestFocus/>
</EditText>

Categories

Resources