I have a UX problem with my layout. I want that is possible that the user can scroll over the compleat layout without a focus change when the keyboard popes up.
This is what the Layout looks like when the activity starts
This is what happens when the user clicks to the Big Text EditText
This is what I want the layout to look like, the positions should stand in the same way as before, but it should be possible to scroll to the bottom with the keyboard open
The rootView of my layout is
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
I also try to add android:windowSoftInputMode="adjustResize" and android:windowSoftInputMode="adjustPan" the the activity in the Manifest.xml but it does not solve my problem.
Related
This question already has answers here:
Bottomsheet with edit text moved up by keyboard
(2 answers)
Closed 2 years ago.
I am using a BottomSheetDialogFragment which contains:
- A RecyclerView with a list of comments made by users
- A EditText at the bottom, where users can write a new comment and post it
When the user taps on the EditText, the keyboard shows up from the bottom.
What i want is the keyboard to push ONLY the EditText, so that the user can see what he's typing, but not push the whole BottomSheetDialogFragment.
You can see the desirable behaviour in the Facebook app for example.
I have tried setting different values for setSoftInputMode but all i can achieve is either to move the whole BottomSheetDialogFragment, or to move nothing (leaving the EditText covered).
The easiest way to do this is to not use a BottomSheetDialogFragment but instead to use a regular fragment that covers the entire window or an activity. Fragment or Activity; whichever you prefer doesn't matter as long as you're taking up the whole screen.
When the on-screen keyboard appears, the activity window (by default) resizes to make way for the on-screen keyboard.
Since a BottomSheetDialogFragment has it's gravity set to bottom, when the activity window resizes, it pushes the bottom sheet and all of it's contents upwards.
Here's an example of the simplest layout that can achieve what you're going for
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#80000000" />
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
First is a view with a constant height which imitates the dark area outside of a dialog. No matter how the window resizes this will always be 80dp.
Second is the RecyclerView which resizes based on the remaining available space the LinearLayout has. Pay attention to the attribute android:layout_weight.
Third is EditText which has a constant height of wrap_content. Again No matter how the window resizes this will always be the same height. Since the RecyclerView will take up as much space as it can, this EditText will remain at the bottom of the screen.
Once the window resizes due to the on-screen keyboard appearing, the LinearLayout will resize and recalculate it's children's sizes. Since the View and the EditText has a constant height it will have to make the RecyclerView smaller making it appear like the EditText moved upwards.
You don't have to use a LinearLayout to do this, you can achieve the same effect with any other layout. The key point here is to use a layout that takes up the whole screen.
My layout looks something like this
<LinearLayout>
<Toolbar/>
<Scrollview>
<More views including a edittext in the bottom/>
</Scrollview>
</LinearLayout>
The problem is that whenever I select the editext to type something the softkey pushes the edittext up, which is how it's supposed to work but the entire layout is pushed up along with it.. I want to keep the toolbar on the screen, just like how it is in WhatsApp where the toolbar remains on the screen when the edittext is pushed up and down by the softkey.
just set
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false">
and also add this in your linearlayout
android:windowSoftInputMode="adjustPan"
I have the following layout in an activity.
<CoordinatorLayout ...>
<ScrollView ...>
<LinearLayout
...
android:orientation="vertical">
<!-- Some stuff -->
<EditText ...>
<!-- Some more stuff -->
<View
android:id="#+id/keyboard_extender"
...>
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/bottom_sheet"
android:orientation="vertical"
...
app:layout_behavior="android...BottomSheetBehavior">
<!-- Even more stuff -->
</LinearLayout>
</CoordinatorLayout>
and I want that the keyboard shouldn't push up the bottom_sheet but it should push up the keyboard_extender. Please note that the bottom_sheet is not a BottomSheetDialog but just a view using the android.support.design.widget.BottomSheetBehavior. This can't be changed to a BottomSheetDialog because I want the rest of the screen to remain active at the same time as the bottom_sheet
I never set the visibility of the bottom_sheet to View.GONE. I only change its state from BottomSheetBehavior.EXPANDED to BottomSheetBehavior.COLLAPSED and back. Also, I want the bottom_sheet to be visible only when the keyboard isn't.
Since I need that the keyboard_extender should always be above the keyboard, I have set in the AndroidManifest.xml that android:windowSoftInputMode="adjustResize" (which I assume is unavoidable)
I have a method which when called should hide the keyboard and show the bottom_sheet, but the problem I'm facing is that the bottom_sheet starts animating to BottomSheetBehavior.EXPANDED at the same time that the keyboard starts hiding, and when the keyboard starts hiding, the screen is actually resized because of the windowSoftInputMode="adjustResize" and the bottom_sheet starts expanding from the top of the keyboard and it doesn't move down along with the keyboard. So, when the keyboard completely hides, the bottom_sheet is actually sitting in the middle of the screen (just above the height of the keyboard).
Ideally, I'd like that the keyboard starts hiding and the bottom_sheet starts expanding at the same time, but the bottom_sheet starts expanding from the bottom of the screen and not the top of the keyboard.
The very hacky fix I'm currently using to overcome this issue is to delay the expanding of the bottom_sheet by SoftInput.KEYBOARD_POPUP_DELAY, which seems to be working for the time being. Is there any cleaner alternative?
I have a an EditText with a drawable background (A rectangle shape with corners and a color, nothing fancy)
Case 1 When the EditText gets focus on click, view shifts above but the soft keyboard still partially overlaps it so that the hint is visible properly but the background is trimmed.
Case 2 (Inside a fragment, coz this issue does not occur in an Activity) If I press next from an edit text above the target EditText the background is again trimmed and the keyboard is just touching the bottom of the hint.
I have enclosed it inside a ScrollView, tried android:windowSoftInputMode="stateAlwaysHidden|adjustResize" (with different combinations too) but nothing seems to work.
Is there a way to override the y-axis by which the view is pushed when soft keyboard opens?
Half of the job is done by Scrollview itself,
Try to writing these line in you onFocusChanged method of edittext
editText.requestLayout();
getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
and your .xml would be like -
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ScrollView
android:layout_height="match_parent"
android:layout_width="match_parent"
android:weightSum="1">
.... your editetexts here...
</ScrollView>
</LinearLayout>
I have two buttons "Submit" and "Reset" on top of the ui and below this is my form. The problem is when i open my keyboard, the form scrolls up and goes below the top buttons layout. What should be the problem? I want to show buutons on top only.
try this
Replace to RelativeLayout to Linearlayout With orientation Vertical.
you can try to prevent the keyboard from scrolling up your form, so the keyboard will be above your layout by doing this :
add this to your manifest
<activity
android:name="yourActivity"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateVisible|adjustPan"/>
then put this inside your ScrollView
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:isScrollContainer="false">
</ScrollView>
if any trouble leave a comment !
Good luck