Done key not showing up on keyboard - android

I am making an Android app and want the done key to show up on the keyboard when the user is typing into the keyboard.
This is the XML code for the EditText:
<EditText
android:id="#+id/answer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="center_horizontal"
android:textColor="#ffffff"
android:layout_marginBottom="113dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:imeOptions="actionDone"
/>
I thought that adding the android:imeOptions="actionsDone would have the done button appear, but instead the enter button is there and when it is pressed, a new line is created in the EditText. What is the issue?

You will not get done by adding imeOptions.
Add the below attribute to your EditText:
android:singleLine="true"
This will make your EditText a single line and you will see the Done button if that is the only EditText or last EditText. If there are multiple EditText items, then you will see Next button.

Related

Prevent EditText from going to new line when 'Space' is tapped

I want to have an EditText which is multi Line and First Letter of a Sentence to be capital. I'm using:
<EditText
android:id="#+id/editText2"
android:layout_width="300dp"
android:layout_height="150dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="32dp"
android:layout_marginTop="67dp"
android:background="#ddebed"
android:ems="10"
android:inputType="textMultiLine|textCapSentences"
android:singleLine="false"
android:text="#string/same" />
I can acheive both: MultiLine and CapSentences.
But, When I press 'Space key' after a word, It goes to a new line.
How do I prevent it?
The android:text="#string/same" refers to <string name="same">\n \n \n Regards: Principal</string>
So, The problem is being caused by \n's.
I want to have an EditText which has some already typed text in next Line, And Allow User to enter some text in First 'n' lines.
Use android:maxLines="1" and android:inputType="text"
Your Edittext should look like below.
<EditText
android:id="#+id/editText2"
android:layout_width="300dp"
android:layout_height="150dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="32dp"
android:layout_marginTop="67dp"
android:background="#ddebed"
android:ems="10"
android:maxLines="1"
android:inputType="text|textCapSentences"
android:text="#string/same" />
OR
If you are looking for multilines you can edit your edittext as
android:inputType="text|textMultiLine|textCapSentences"
Similarly you can increase android:maxLines="2"
I have checked it out. You can use above code with some below modifications.
EditText editText = (EditText)findViewById(R.id.editText2);
editText.setSelection(0);
It will move your cursor to position 0. Also try to increase maxlines value. I have checked it my end and it's working fine.
Try using this tag in xml.
android:singleLine="true"
You can Add Two Hidden Spaces Before \n's.
To add a Hidden space: Alt + 0160 (Numpad keys).
So, When User is typing something, The Hidden Spaces will keep moving and UserText won't be able to reach to \n.

EditText Next Focus is not woking

I have few EditText in a same screen. Next soft key button is not there. Enter soft key is there but, it was not going to next EditText whenever I am pressing on that button. And after last EditText reached, I want to hide the soft keyboard. What should I do to achieve that. I found many questions and solution in stackoverflow. Nothing working for me.
Edittext Code:
<EditText
android:id="#+id/vehicle_number"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:imeOptions="flagNoExtractUi|actionNext|actionGo|actionDone"
android:paddingLeft="5dp"
android:textSize="25dp"
android:maxLength="12"
android:hint="GA-00-A0000"
android:digits="1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ-"
android:nextFocusForward="#+id/vehicle_color"
android:inputType="textCapCharacters"
android:background="#drawable/edittext_rect_yellow_border" />
Tried java code also,
vehicle_number.setNextFocusDownId(R.id.vehicle_color);
I fixed myself. The solution is below. Now the 'Next' soft key displaying.
Removed
android:inputType="textCapCharacters"
Added
android:maxLines="1"
android:singleLine="true"
For Capital Characters
vehicle_number.setInputType(InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
Solution
<EditText
android:id="#+id/vehicle_number"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:imeOptions="flagNoExtractUi"
android:paddingLeft="5dp"
android:textSize="25dp"
android:maxLength="12"
android:hint="GA-00-A0000"
android:maxLines="1"
android:singleLine="true"
android:digits="1234567890qwertyuioplkjhgfdsazxcvbnm-"
android:background="#drawable/edittext_rect_yellow_border" />

EditText gaining focus but my typing doesn't append

I have an EditText and have a hint. When I tap on the EditText, the keyboard appears, though, as I type neither the hint goes away nor my typing goes into view. It's like my input is going to /dev/null. My EditText is inside a ListView cell, if it helps. Here is my layout:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:background="#00000000"
android:id="#+id/aboutView"
android:layout_gravity="center_horizontal|bottom"
android:layout_centerHorizontal="true"
android:layout_below="#+id/headerFrame"
android:layout_marginTop="12dp"
android:gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:textSize="14dp"
android:layout_marginBottom="12dp"
android:hint="Tell something about yourself..." />
Why can this be?
Found the solution here: EditText in Listview loses focus when pressed on Android 4.x
I don't know the exact reason, but I wasn't the only one suffering from EditText focus problems when inside a ListView. I've added android:windowSoftInputMode="adjustPan" to my activity in manifest file and the problem went away.

Why isn't my softKeyboard coming up automatically in android

Strangely, my soft keyboard is not opening automatically.On SO I have looked they seem to ask on How to hide Keyboard...?
I would like to get the keyboard automatically focues on the Text Box.
Here is what I have on my XML
android:id="#+id/msg"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cursorVisible="true"
android:gravity="left"
android:imeOptions="actionDone"
android:inputType="textMultiLine"
android:maxLength="255"
android:paddingLeft="5dp"
android:scrollbars="vertical"
android:textColor="#000000"
android:textColorHint="#000000"
android:textSize="25sp" />
How to fix this?
You stated "Text box".. If you meant "EditText" than one possibility will be to see if there is any other view that is requesting the focus.
You can also try to add view.requestFocus programatically.
I suppose you need add:
android:textCursorDrawable="#null"
to EditText to see the cursor
Simply add this code <requestFocus /> To the EditText you want to be focused and it will open the keyboard for that field:
<EditText
android:id="#+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPassword" >
<requestFocus />
</EditText>
Add the following line inside your Activity tag in AndroidManifest.xml,
android:windowSoftInputMode="stateAlwaysVisible"
Developer site says,
"stateAlwaysVisible":The soft keyboard is made visible when the user chooses the activity — that is, when the user affirmatively navigates forward to the activity, rather than backs into it because of leaving another activity.
reference
https://stackoverflow.com/a/1510005/1665507
http://developer.android.com/guide/topics/manifest/activity-element.html
http://blog.vogella.com/2010/10/25/android-windowsoftinputmode/
why you have to open a keyboard on a code. it will automatically get opened if you are on EditText

How to roll up EditText?

I have an EditText defined in my half screen RelativeLayout. and it appears perfectly. However, if I start typing typing more than 1 line in my EditText, it makes my entire entire window expand. I want the EditText to roll up and only show the currently typing line? Like in Facebook Messager, I want the EditText to keep scrolling itself as the user types new lines? HEre is how I implemented the EditText
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#+id/button1"
android:ems="10"
android:focusable="true"
android:inputType="textMultiLine" />
Just set
android:maxLines="1"
This makes the TextView be at most this many lines tall.

Categories

Resources