I don't have any sample code for this case, because I don't know how this work.
A screenshot will explain this much clearer.
I'm trying to create an input like a Telegram.
Once the sticker button is clicked, hide the keyboard and show a panel with the same height.
The current way that I'm doing will cause the window jumping around.
Because when the panel is open, the input will be pushed up
When the keyboard is hidden, the input will go to the bottom then pushed up after the sticker panel shows up.
This is what I have right now
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/inputLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:showIn="#layout/activity_main">
<LinearLayout
android:id="#+id/inputContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.textfield.TextInputEditText
android:id="#+id/inputBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
<RelativeLayout
android:id="#+id/galleryContainer"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/send_panel_color"
>
</RelativeLayout>
adjustResize
The activity's main window is always resized to make room for the soft keyboard on screen.
adjustPan
The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.
This might help you one of them !
<activity android:windowSoftInputMode="adjustResize"> </activity>
<activity android:windowSoftInputMode="adjustPan"> </activity>
Taken the help from
Other member of Stackoverflow
Related
TL;DR: soft keyboard should overlap a bottom-anchored view instead of pushing it up. Gitlab link for an mcve.
Summary:
I have an AppCompatDialogFragment (androidx) which appears fullscreen on phones and has fixed dimensions on tablets (using dialog?.window?.setLayout(width, height) in case this matters). The dialog's layout has some content placed in a ScrollView and a button-like layout anchored at the bottom (complete XML structure see below).
Side note: the superclass of the AppCompatDialogFragment in question calls setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN)on its Window.
The problem:
When the soft keyboard appears as a result of some text input receiving focus, it pushes the complete layout up, including the bottom-anchored view that I want overlapped by the soft keyboard. For some reason, the issue only affects phones, on tablets the soft keyboard correctly overlaps everything including the bottom-anchored view without any additional adjustments or flags.
What I have tried (without any success):
setting android:windowSoftInputMode="adjustNothing" (tried other flags "just in case" as well) for the Activity in question, also tried to apply them in code
setting android:isScrollContainer="false" on the ScrollView and its parent
combinations of the above
looking for similar questions like this one and confirming the proposed solutions didn't work
Here's the layout in question (note: I omitted many unrelated attributes to keep the snippet reasonably sized; everything is positioned vertically matching the elements' order. The <include> elements contain the text inputs):
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:id="#+id/toolbar"
android:layout_height="?attr/actionBarSize"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="#id/bottom_layout"
app:layout_constraintTop_toBottomOf="#id/toolbar"
android:isScrollContainer="false"
android:scrollbarStyle="outsideOverlay">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include
layout="#layout/some_layout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<include
layout="#layout/some_layout_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
<!-- I want this one to be overlapped by the soft input, but it's just pushed up -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/bottom_layout"
app:layout_constraintBottom_toBottomOf="parent">
<View
android:layout_width="match_parent"
android:layout_height="#dimen/divider"
android:background="#color/dark_grey" />
<TextView
android:layout_width="match_parent"
android:layout_height="#dimen/some_dimen"
android:foreground="?attr/selectableItemBackground"
android:text="#string/text" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
The question: how do I force the soft keyboard to overlap the layout anchored at the bottom on all devices?
Please comment if you need any additional details.
EDIT: here's a minimal demo app that reproduces the issue: https://gitlab.com/Droidman/soft-keyboard-issue-demo
Try adding the following line to onCreateView() of DemoDialog:
dialog.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_NOTHING)
It is important to apply this change to the window of the dialog and not to the window of the activity.
With this in place, this is what I see on an Nexus 6 emulator running API 29 using your MCVE:
You may need to work with the placement a little, but this should help.
Let's look under the hood a little. For a phone and a tablet, the soft input mode is zero in onCreateView(). This value corresponds to SOFT_INPUT_ADJUST_UNSPECIFIED. The documentation for SOFT_INPUT_ADJUST_PAN explains what happens when the soft input mode is unspecified (emphasis is mine.)
Adjustment option for softInputMode : set to have a window pan when an input method is shown, so it doesn't need to deal with resizing but just panned by the framework to ensure the current input focus is visible. This can not be combined with SOFT_INPUT_ADJUST_RESIZE ; if neither of these are set, then the system will try to pick one or the other depending on the contents of the window.
Looking at the value of the soft input mode in onStart() (dialog?.window?.attributes?.softInputMode) shows the value selected by the system for the phone is SOFT_INPUT_ADJUST_RESIZE) and the value selected for the tablet is SOFT_INPUT_ADJUST_PAN. This explains the difference that is seen between phones and tablets.
So, always setting the soft input mode to SOFT_INPUT_ADJUST_PAN looks like the best solution although SOFT_INPUT_ADJUST_NOTHING also works and may be preferable for certain layouts.
Add this to your class inside the tags in the AndroidManifest in your Class:
android:windowSoftInputMode="stateHidden|adjustResize"
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"
I am developing a native Android app that is a wrapper for a webpage. It works pretty well, but there is an issue where the soft keyboard (Android keyboard) appears over the bottom of the webview, which makes it impossible to see what you are writing if you are trying to fill out something near the bottom of the webview.
Please see image below. Here I've clicked a textarea that is impossible to reach while the keyboard is open:
The code for this view is:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp" tools:context=".PetpulseMainActivity">
<WebView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/petpulseWebView" />
</RelativeLayout>
I've tried switching the RelativeLayout with ScrollView and other approaches I've found, but for some reason the keyboard is always rendered on top of the view.
AndroidManifest.xml:
<activity
android:name=".PetpulseMainActivity"
android:label="#string/app_name"
android:screenOrientation="portrait">
[...]
</activity>
It's a known bug as refered in :
https://code.google.com/p/android/issues/detail?id=5497
To avoid it, remove the FullScreen theme of your activity
Update:
From FLAG_FULLSCREEN
Window flag: hide all screen decorations (such as the status bar)
while this window is displayed. This allows the window to use the
entire display space for itself -- the status bar will be hidden when
an app window with this flag set is on the top layer. A fullscreen
window will ignore a value of SOFT_INPUT_ADJUST_RESIZE for the
window's softInputMode field; the window will stay fullscreen and will
not resize.
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