I have followed this solution on preventing edit text from taking focus on activity startup. And implemented it as such
<LinearLayout
android:layout_width="0px"
android:layout_height="0px"
android:focusable="true"
android:focusableInTouchMode="true"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/amount"
android:text="#string/zero"
android:gravity="end|center_vertical"
android:nextFocusUp="#id/amount"
android:nextFocusLeft="#id/amount"
android:inputType="numberDecimal"/>
Notice the android:inputType="numberDecimal". If I remove that then upon startup the focus is not taken, however if it is there then focus is taken. Is there any way to get decimal edit text to not take focus upon startup? I am using API > 23 if it is of any concern.
And just as a side note from looking at answers other people provided to similar questions, I want my field to not take focus. I do not want to only hide the soft keyboard but keep the focus.
Add this to your activity tag in manifest
android:windowSoftInputMode="stateHidden|adjustResize"
Code looks like in manifest
<activity
android:name=".ActivityName"
android:windowSoftInputMode="stateHidden|adjustResize" />
This will help hide soft keyboard at startup
And add these tags to your root layout rather than parent layout
android:focusable="true"
android:focusableInTouchMode="true"
Related
I spent hours debugging the same issue described in these SO questions:
Android: How do I prevent the soft keyboard from pushing my view up?
How to avoid soft keyboard pushing up my layout?
Android: How do I prevent the soft keyboard from pushing my view up?
The generally accepted answer is to add android:windowSoftInputMode="adjustPan" to the manifest activity declaration. This works to make the screen stay put when the keyboard is opened, however it does not stop the screen from scrolling when text is entered that has more lines than the screen can display. Here is what I see when I implement that solution:
The header remains when the keyboard opens, however if you type a bunch of lines the header eventually scrolls off the top of the screen.
I tried Googling this problem to try and solve it and none of the solutions worked. Then I managed to solve it by doing the opposite of what the accepted answer above said.
For reference, my layout xml file:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toBottomOf="#id/header"
android:fillViewport="true">
<EditText
android:id="#+id/noteText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:windowSoftInputMode="adjustPan"/>
</ScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
My manifest:
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
android:resizeableActivity="true"
tools:targetApi="n"/>
I solved this by changing the manifest activity declaration to remove the android:windowSoftInputMode="adjustPan" line from the manifest:
<activity android:name=".activity.MainActivity"
android:screenOrientation="portrait"
android:resizeableActivity="true"
tools:targetApi="n"/>
...and now everything works as expected, the header stays on the screen when the keyboard was open and text was entered.
Hoping that I can save someone the time it took me to figure this out. Here is what it looks like after fixing the manifest:
I am having a EditText in the hierarchy of
<CoordinateLayout>
...
<NestedScrollView>
...
<RelativeLayout> <!-- This is inside an included xml layout -->
...
<EditText
android:id="#+id/rateCalculator"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:background="#color/colorPrimary"
android:inputType="number"
android:maxLength="5"
android:gravity="center"
android:textColor="#FFFFFF"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:paddingLeft="60dp" />
</RelativeLayout>
</NestedScrollView>
</CoordinateLayout>
The EditText is being covered by the android soft-keyboard when it is being on focus! So I am unable to see what is being typed while typing!
Update:
This is my manifest code. Doesn't help!
<activity
android:name=".OfferRide"
android:label="#string/title_activity_offer_ride"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan"
android:theme="#style/AppTheme.NoActionBar" />
Here is the full doc: http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft
android:windowSoftInputMode=["stateUnspecified",
"stateUnchanged", "stateHidden",
"stateAlwaysHidden", "stateVisible",
"stateAlwaysVisible", "adjustUnspecified",
"adjustResize", "adjustPan"] >
How the main window of the activity interacts with the window
containing the on-screen soft keyboard. The setting for this attribute
affects two things: The state of the soft keyboard — whether it is
hidden or visible — when the activity becomes the focus of user
attention. The adjustment made to the activity's main window — whether
it is resized smaller to make room for the soft keyboard or whether
its contents pan to make the current focus visible when part of the
window is covered by the soft keyboard. The setting must be one of the
values listed in the following table, or a combination of one
"state..." value plus one "adjust..." value. Setting multiple values
in either group — multiple "state..." values, for example — has
undefined results. Individual values are separated by a vertical bar
(|). For example:
<activity android:windowSoftInputMode="stateVisible|adjustResize" . . . >
Values set here (other than "stateUnspecified" and
"adjustUnspecified") override values set in the theme.
Flags:
"stateUnspecified"
"stateUnchanged"
"stateHidden" - The state of the soft keyboard — whether it is hidden or visible — when the activity becomes the focus of user attention.
"stateAlwaysHidden"
"stateVisible"
"stateAlwaysVisible"
"adjustUnspecified"
"adjustResize"
Or sometimes java will do that:
EditText edtView=(EditText)findViewById(R.id.editTextConvertValue);
edtView.setInputType((InputType.TYPE_NULL);
Take a look:
https://stackoverflow.com/a/6122733/4409113
Removing the gravity from the EditText made it! It seems to be a bug.
<EditText
android:id="#+id/rateCalculator"
android:layout_width="wrap_content"
android:layout_height="48dp"
android:background="#color/colorPrimary"
android:inputType="number"
android:maxLength="5"
android:textColor="#FFFFFF"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:paddingLeft="60dp" />
You can try adjustPan, adjustResize options available for windowSoftInputMode in your AndroidManifest as follows:
<activity
...
android:windowSoftInputMode="adjustPan" >
</activity>
You can learn more about it from here
Depending on behavior you want to get, you can use android:windowSoftInputMode="adjustResize" or android:windowSoftInputMode="adjustPan" on your activity declaration in Manifest.
This question already has answers here:
Android soft keyboard covers EditText field
(15 answers)
Closed 7 years ago.
I define EditText on the button of my application
Its look like this:
But when i focus on the EditText of the Notes the keyboard is open and cover all my EditText and i can't see what i typing in the EditText.
When i hide the keyboard i see the right text that i typed in.
The xml of the LinearLayout of the EditText:
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Notes:"
android:id="#+id/textView"
android:textColor="#000000" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/editText"
android:focusable="true" />
</LinearLayout>
You might need to use windowSoftInputMode attribute in your activity in the manifest. Somelike this:
<activity name="YourActivity"
android:windowSoftInputMode="adjustPan">
...
</activity>
Check those links:
Android soft keyboard covers edittext field
http://android-developers.blogspot.com/2009/04/updating-applications-for-on-screen.html
The only solution to this is to put your text box in a different place.
Think about it... Do you really want your text box ABOVE your keyboard?
This is a fairly common issue, and it something that should always be taken into account when designing your layout.
so this solve my problem ( thanks to #Coeus )
I define on the manifest this line
android:windowSoftInputMode="adjustPan"
I have a table whose tapping on a cell changes its content and displays some edit texts. The first of these edit texts requests the focus, but oddly when I tap on it, the keyboard doesn't show. It is when I tap the others edit texts though. What should I do? Here is how I implemented my first edit text.
<EditText
android:id="#+id/editContent"
android:layout_width="match_parent"
android:layout_height="120dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:gravity="top"
android:inputType="textMultiLine" >
</requestFocus>
</EditText>
When I don't request the focus, there is also a strange behaviour: it opens the keyboard when I tap it but my edit text loses the focus and I've to tap it again to write in it.
I found the problem, it was because of this line in the Activity block of the Manifest :
android:windowSoftInputMode="stateHidden"
I changed it by :
android:windowSoftInputMode="adjustPan"
Works well now.
I have added a LinearLayOut having some buttons My screen is RelativeLayOut it self
Here is the code for that linear layout manager
<LinearLayout
android:orientation="horizontal"
android:gravity="bottom"
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:id="#+id/Footer"
android:layout_marginBottom="5dp">
Here is the problem:
There is an EditText component on the top and it pops a soft keyboard on the screen , and brings my Footer manager on top of the keyboard and eventually SHATTERS my whole UI.
What is the exact solution?
P.S. I have removed android:gravity="bottom" and android:layout_alignParentBottom="true" one by one but with hard luck i did not get desired result.
Thanks
Add android:windowSoftInputMode="adjustPan" to manifest - to the corresponding activity:
<activity android:name="MyActivity"
...
android:windowSoftInputMode="adjustPan"
...
</activity>
You probably want
<activity
...
android:windowSoftInputMode="adjustNothing">
</activity>
That will prevent any layout changes when the soft keyboard is shown.
There is probably some confusion over this since it's currently missing from the documentation at http://developer.android.com/guide/topics/manifest/activity-element.html#wsoft