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.
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 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"
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'm trying to make something like the image below, where the keyboard automatically opens when the activity starts and the EditText and the send button stick to the keyboard.
Use the below code to pop up the soft keyboard automatically when an activity launches
InputMethodManager imm = (InputMethodManager)getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(youredittext, 0);
Make sure that you have not define android:windowSoftInputMode="stateHidden" in your manifest.xml.
To make an Edittext attach with the footer,use the following code:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#f3f3f3"
android:paddingBottom="10.0dip"
android:paddingTop="10.0dip"
android:id="#+id/bottom_bar" >
<EditText
android:id="#+id/et_send_bar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10.0dip"
android:layout_toLeftOf="#+id/ib_send"
android:hint="Enter Message"
android:singleLine="true" />
<ImageView
android:id="#+id/ib_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/et_send_bar"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/et_send_bar"
android:layout_marginBottom="1px"
android:layout_marginRight="10.0dip"
android:layout_marginTop="1px"
android:background="#drawable/chatsend_bg"
android:paddingBottom="5.0dip"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="5.0dip"
android:src="#drawable/ic_send_dark_normal" />
</RelativeLayout>
To show Keyboard at start of Activity you need to use like this:
<activity android:name="com.your.package.ActivityName"
android:windowSoftInputMode="stateVisible" />
From Android Docs:
stateVisible
The soft keyboard is visible when that's normally appropriate (when
the user is navigating forward to the activity's main window).
To hide Keyboard at start of Activity you need to use like this:
In your AndroidManifest.xml:
<activity android:name="com.your.package.ActivityName"
android:windowSoftInputMode="stateHidden" />
From Android Docs:
stateHidden
The soft keyboard is hidden 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.
This setting will hide soft keyboard when user enters new Activity (even if EditText control gains the focus). Soft keyboard will be shown only when user clicks the edit box control.
I have also found another solution for moving up layout components when Soft keyboard appers.
It can be achieved using adjustResize attribute in AndroidManifest.xml
Main purpose of adjustResize attribute is the activity's main window is always resized to make room for the soft keyboard on screen.
To show Keyboard and moved up EditText at start of Activity you need to use like this:
<activity android:name="com.your.package.ActivityName"
android:windowSoftInputMode="adjustResize" />
i think it will works for you:
Add this statement in manifest file to your Activity:
android:windowSoftInputMode="stateHidden"
<activity
android:name="ConversationActivity"
android:label="#string/title_activity_conversations"
android:launchMode="singleTask"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden" />
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