Android ScrollView, under Action Bar on Softkeyboard - android

I've read several discussions around this issue and it has to do with the android:windowSoftInputMode="stateHidden|adjustResize" (as well as adjustPan) of the manifest file when attempting to get a ScrollView of a LinearLayout to adjust when the keyboard is shown.
I have a layout that has a LinearLayout inside of a ScrollView that contains 10 LinearLayout sections (TextView/EditText views). I have tried every combination I have read about and no matter what, when the keyboard is opened as a result of clicking on the top EditText, the view is adjusted (panned) such that the top field is behind the action bar. I can scroll to the bottom of the page, but I can't get to the top EditText - I can only scroll to the 2nd one. I can try and pull down and I can start to see the top EditText but can't get it to show unless I dismiss the keyboard (which obviously I can't edit the text then).
<ScrollView
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"
tools:context="com.example.myproject.FirstActivity"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
tools:showIn="#layout/activity_work"
android:layout_gravity="center_horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="x1"
android:layout_weight="50"/>
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/work_one"
android:hint="0"
android:gravity="right"
android:selectAllOnFocus="true"
android:textAlignment="gravity"
android:layout_weight="50" />
</LinearLayout>
.
. (9 more of these)
.
</LinearLayout>
</ScrollView>
UPDATE:
so I tried: android:windowSoftInputMode="adjustResize" and / or android:windowSoftInputMode="adjustPan" and the soft keyboard shifts the top fields under the action bar.
Thoughts?

Try either android:windowSoftInputMode="adjustResize" or android:windowSoftInputMode="adjustPan"
From the doc
"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.
I copied the answer from this Stack Overflow answer

Related

EditText keyboard scroll margin

There is a character counter under the pink line, which I would like to see while typing, but it's covered by the keyboard. Everything is inside a scroll view, and the text field scrolls up when focused, but I want to make it "overscroll" - how can we adjust the scroll offset, or whatever it's called?
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<EditText
android:id="#+id/answer_text"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<TextView
android:id="#+id/length_limit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="viewEnd"
android:maxLength="250"/>
</LinearLayout>
Look at this link Move layouts up when soft keyboard is shown?
or if you want to change margins check this
KeyBoard changing
And for implementing that :
onResume

Android Soft Keyboard not showing all `EditText`

First off all let me say that I've tried in the manifest android:windowSoftInputMode="adjustPan|stateHidden" and android:windowSoftInputMode="adjustResize|stateHidden" and the result is the same.
I have a layout with an Header and a Footer and in between I have an ScrollView. Inside this, I have a RelativeLayout and inside this layout, I have one EditText and a LinearLayout containing another EditText (this layout makes sense in my app).
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scroll"
android:layout_below="#+id/header"
android:fillViewport="true"
android:layout_above="#+id/footer">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="40dp">
<EditText
android:id="#+id/one"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:background="#drawable/edittextback"
android:layout_marginBottom="40dp" />
<LinearLayout
android:id="#+id/placeholder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/one"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
android:layout_marginBottom="40dp">
<EditText
android:id="#+id/two"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/edittextback"
android:gravity="center"/>
</LinearLayout>
</RelativeLayout>
</ScrollView>
When I enter the activity and start entering text in the first edittext, the keyboard pops up, the scroll goes up a little so the I can see the text that I'm inserting. The problem is that the edittext is not all visible (I mean the bottom boundary). The keyboard stays just bellow the inserted text and not bellow the bottom of the edittext.
Now, since I already have the keyboard open, I scroll a bit so that I can see the top of the second edittext. When I touch the second edittext, it gains focus, and now, it automatically scrolls a bit not like the first edittext, that is, just enough to see the inserted text, but to the bottom of the edittext making the edittext all visible. This is what I want.
How can I make the behavior to be show always all the edittext?

How to move up the whole layout when keyboard shown?

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_gravity="bottom"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</FrameLayout>
in manifest:
android:windowSoftInputMode="adjustPan"
Initial behavior:
Current behavior:
Desired behavior:
How to achive desired behavior of layout? adjustResize unsuitable because this option resizes layout.
Thank you for answers!
The only way to obtain that result is resize layout.
Use android:windowSoftInputMode="adjustResize"
You probably want to take a look at this answer. A suggestion from it:
Set Window SoftInput Mode property to adjustPan and adjustResize
<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>
try this one in your manifest:
android:windowSoftInputMode="adjustResize|stateUnchanged"
the check if the layout that contain EditText and Button is RelativeLayout.
Try to change FrameLayout to RelativeLayout with alignParentBottom="true" property in your LinearLayout:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</RelativeLayout>
You won't be able to implement that with adjustPan, because from the official guide
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.
Your Button is below your current focus EditText
by removing below line from activity and android:windowSoftInputMode from manifest, I got whole layout scrolling which was previously hiding by
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
please check this output video link:
https://mega.nz/#!TpRCWZjY!TqDzv0Yn3Q24PR1JAdH8kRVeDf2iSa1LQbNBgF0SVHk
I don't believe there is a simple way to do this. At least not as simple as setting a flag.
I had a similar situation of wanting the keyboard to rise to the level of Views well below the selected EditText. I ended up using this answer:
How to check visibility of software keyboard in Android?
and manually adjusting my View sizes when the keyboard becomes visible.
Just use this property in activity
android:windowSoftInputMode="adjustPan"

Android layout hidden on keyboard show

I have a strange problem with my layout. When i tap on EditText, keyboard is shown but my EditText stay on bottom, when I tap on back to hide keyboard, keyboard hides and EditText go up where it should be when i want to input text. When I tap again, keyboard is shown and EditText goes down behind the keyboard...
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:above="#+id/rl_commands">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</ScrollView>
<RelativeLayout
android:layout_width="match_parent
android:layout_height="24dp"
android:id="#+id/rl_commands"
android:alignParentBottom="true">
<EditText
............/>
<Button
.........../>
</RelativeLayout>
</RelativeLayout>
Also in manifest.xml I added adjustResize but problem stays.... What i want is that when I tap(focus) EditText and keyboard shows, RelativeLayout go up to see what I am typing. And after keyboard hide to resize RelativeLayout again and RelativeLayout go to bottom of screen. Like in viber...
Add this line in activity tag inside manifest.xml file
android:windowSoftInputMode=adjustPan
for more you can refer :Android Documentation
Please try with this line in your manifest.xml file:
android:windowSoftInputMode=adjustPan|adjustResize

Soft-keyboard appears every time layout becomes visible

I have two layouts within a fragment that I switch back and forth between by making one invisible and the other visible and visa versa. When the layout that contains an EditText becomes visible the soft keyboard automatically pops up. I have used the following in the manifest but it didn't help.
android:windowSoftInputMode="stateUnchanged"
I never explicitly request focus on the EditText and have even tried requesting focus on something else to no avail.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
android:id="#+id/container">
<LinearLayout android:id="#+id/dial_pad_ll"
android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:layout_centerInParent="true"
android:background="#1E1E1E" android:layout_marginLeft="20dp" android:layout_marginRight="20dp">
<EditText android:layout_height="wrap_content" android:id="#+id/search_et"
android:layout_width="match_parent" android:layout_alignParentTop="true"
android:layout_marginTop="20dp" android:layout_marginBottom="10dp" >
</EditText>
<!-- Other widgets here -->
</LinearLayout>
<!-- Other Layout Here -->
</RelativeLayout>
Anyone know how to prevent this? Thanks.
Edit: I should also have mentioned that this doesn't happen the first time. I open layout 1 with the edit text, make it invisible, make it visible again, then the keyboard pops up.
try adding this to your activity.
this.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

Categories

Resources