Remove auto focus from EditText - android

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

Related

Android EditText was not completely visible when keyboard appears

My EditText was not completely visible when the keyboard appears, it was visible till focus but is there any possibility to view complete EditText.
Layout
<ScrollView
android:id="#+id/scrollvew_direct"
android:isScrollContainer="true"
android:layout_height="wrap_content">
<EditText
android:id="#+id/edt_employers_name"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:inputType="text"
android:maxLength="100"
android:hint="#string/dir_deposit_6"
android:textSize="#dimen/edittextsize_sub"
android:gravity="center"
android:layout_gravity="center"
android:textColor="#color/main_header"
android:textColorHint="#color/hint_color_light"
android:background="#drawable/edittext_style"/>
</ScrollView>
In mainfest
<activity
android:name=".activityname"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustResize"
android:theme="#android:style/Theme.Holo.Light.NoActionBar"/>
please guide me for proper solution.
In you activity tag of the manifest , add this property
android:windowSoftInputMode="adjustResize"
Edited :
Edittext height is not fully matched to the background drawable
make edittext as
android:layout_height="match_parent" or
android:layout_height="wrap_content"
and check it for me it is working
In you activity tag of the manifest , add this property
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"

Automatically popup software keyboard when the app starts

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.

Android Edittext - Keyboard overlap the edittext when the edittext exceed the max length

In my Activity, I have a EditText field that will be pushed up by keyboard so user can input like normal. But just when user enter exceed the max length of this EditText, the EditText field being pulled down and behind the keyboard, so user cannot see the field anymore.
My xml layout:
<EditText
android:id="#+id/edtDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/button_login_customize"
android:ems="15"
android:fontFamily="OpenSans-Light"
android:hint="#string/td_hint_description"
android:imeOptions="actionDone"
android:inputType="textCapSentences"
android:maxLength="150"
android:paddingBottom="15dp"
android:paddingLeft="16dp"
android:paddingTop="15dp"
android:singleLine="true"
android:textColorHint="#drawable/hint_text_color"
android:textSize="#dimen/text_size_13" />
And my Manifest:
<activity
android:name=".activities.TransferEnterDetailsActivity"
android:configChanges="locale"
android:screenOrientation="portrait"/>
And I'm in Full Screen theme.
Any suggestion is appriciated. Thank you very much.
Add this property in your .xml file,
I was having same problem than i solved as below ,
<EditText
android:id="#+id/editMsj"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="top|left"
android:hint="Enter Message"
android:inputType="textMultiLine|textPostalAddress"
android:minHeight="200dip"
android:padding="5dip"
android:scrollbars="vertical"
android:textColor="#color/black"
android:textColorHint="#80000000"
android:textSize="#dimen/font_normal_size" />
in AndroidManifest
android:windowSoftInputMode="stateAlwaysHidden|adjustResize"

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

text keyboard appear even if I have set inputType to number edittext android

I want to display the number keyboard.
Here is my code to do that. (This is an item of my list).
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/checked_list_item_text"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/checked_list_item_quatity"
android:layout_centerVertical="true"
android:textSize="30sp" />
<EditText
android:id="#+id/checked_list_item_quatity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="7dp"
android:gravity="center_vertical"
android:hint="Quantité"
android:focusableInTouchMode="true"
android:inputType="number"
android:maxLength="6"
android:textSize="30sp" />
</RelativeLayout>
When I click on edittext, the keyboard displays the numbers but switches quickly to text and I have to click a second time to get the number keyboard.
This issue occurs only the first time when I open the activity.
Try changing the input mode in your AndroidManifest.xml
I had the same issue when trying to get focus to an edittext field thats inside a listview. Adding android:windowSoftInputMode="adjustPan" in the activity holding the listview solved the problem for me.
<activity android:name=".MyEditTextInListView"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan">
What you have should work , but it could be something on the code side. Maybe you can force it programmatically:
EditText checkedInput = (EditText) findViewById(R.id.checked_list_item_quatity);
checkedInput.setInputType(InputType.TYPE_CLASS_NUMBER);

Categories

Resources