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
Related
I have 2 text fields in the start page. But the first text field gets auto focus after launch. I don't want this. I have seen couple of answers regarding this, but none of that work for me.
My Code
<EditText
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/transparent"
android:drawablePadding="12dp"
android:padding="10dp"
android:ems="10"
android:hint="Username"
android:inputType="textEmailAddress"
android:textColorHint="#android:color/white"
android:layout_marginTop="70dp"/>
I have added two more line here
android:focusable="true"
android:focusableInTouchMode="true"
But still it gets auto focus
Try this use android:windowSoftInputMode="stateAlwaysHidden" in manifest file of your Activity
<activity
android:name=".Youractivity"
android:windowSoftInputMode="stateAlwaysHidden" />
EDIT
I have added two more line here
android:focusable="true"
android:focusableInTouchMode="true"
the above line is used for requesting focus rather than not focusing
I have an editText on the main page. I want the keyboard to open automatically when the app starts and to be focused on that editText. I tried many "solutions" I found on the Internet but nothing helped me.
The keyboard still doesn't appear automatically.
By the way, my editText has the following properties:
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:gravity="left"
android:focusable="true"
android:enabled="true"
android:focusableInTouchMode="true" />
So how do I make the keyboard appear automatically?
You have to do two things (I have just tested this and it works just fine):
1: request focus for the field.
From the activity java file you can do
mTextView = (EditText) findViewById(R.id.textView);
mTextView.requestFocus();
From the XML file you can rewrite your element as follows:
<EditText android:id="#+id/textView">
<requestFocus/>
</EditText>
2: Force the keyboard when showing the activity: in the onCreate method just write this line:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE);
Add android:windowSoftInputMode="stateAlwaysVisible" to your activity tag in the AndroidManifest.xml file
<activity
android:name=".TestActivity"
android:windowSoftInputMode="stateAlwaysVisible" />
Also use requestFocus tag in EditText.
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:gravity="left"
android:focusable="true"
android:enabled="true"
android:focusableInTouchMode="true">
<requestFocus />
</EditText>
Call myeditText.requestFocus() after you initialize your layout on your activity's onCreate() method.
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.
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.
I did the following code in my program:
<RelativeLayout
....>
<EditText
android:id="#+id/EditText"
android:layout_width="150dp"
android:layout_height="37dp"
android:layout_below="#+id/Header"
android:layout_toRightOf="#+id/Button"
android:inputType="number"
android:textSize="14dp" />
</RelativeLayout>
but whenever I tried it on my app, the app will first pop out the numeric keypad, and then a sec later, it will changed to alphabet keypad and the edittext is no longer on focus.
Can anyone help? Thanks!
It sounds like somewhere in your layout or UI code something else is using requestFocus, perhaps another input field that is not of type number.