1

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?

TheDevMan
  • 5,914
  • 12
  • 74
  • 144
  • 2
    add this to your activity in manifest file `android:windowSoftInputMode="stateAlwaysVisible"` – Spring Breaker May 20 '14 at 07:39
  • My other apps that I used EditText doesn't use android:windowSoftInputMode="stateAlwaysVisible" at all... How is it is opening there? – TheDevMan May 20 '14 at 07:51
  • Solved the issue as per @SpringBreaker... Strangely, it works fine on other apps without the manifest change. Not sure why...? – TheDevMan May 21 '14 at 08:39

5 Answers5

1

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.

roiberg
  • 13,629
  • 12
  • 60
  • 91
0

I suppose you need add:

android:textCursorDrawable="@null"

to EditText to see the cursor

Xcihnegn
  • 11,579
  • 10
  • 33
  • 33
0

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> 
  • Am testing it on my code now and it works fine. I had this in my manifest : android:windowSoftInputMode="stateHidden" inside an activity and that prevents your keyboard from popping on any field. If you have that code or anything similar in that activity in manifest then you wont get a keyboard pop. I removed it and added the requestFocus and it pops – Antonis Lambrianides May 20 '14 at 09:13
  • I have it in a different activity. Does this disturb msg activity? – TheDevMan May 20 '14 at 09:16
  • No that shouldnt be a problem. Did you add any code programmatically? Also please post your manifest . Try to make a new test activity and add 2 EditText fields inside. And test it without the request focuse.(btw sometimes requestFocus will be put automatically by android if you dont have anything focused). Try that test activity and see if it pops – Antonis Lambrianides May 20 '14 at 09:21
  • Thanks for the help Antonis Lambrianides... This is exactly I tried for a new app and I have been using the same code for other apps too... It is working fine there.. Strangely for this EditText I am not able to make it work.. Anyways Solved the issue as per @SpringBreaker... – TheDevMan May 21 '14 at 08:42
0

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/

Community
  • 1
  • 1
Spring Breaker
  • 8,233
  • 3
  • 36
  • 60
-1

why you have to open a keyboard on a code. it will automatically get opened if you are on EditText

user3426056
  • 1
  • 2
  • 4