Android layout hidden on keyboard show - android

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

Related

Android resize one part of layout when soft keyboard displayed

I want to create layout which consists in normal condition from image and few EditTexts as displayed in the next image
But when user starts to enter the text I need to change the layout the next way:
Soft keyboard at the bottom of screen,
EditTexts about it but Image is resized according to the size of soft keyboard as displayed here
How can I do it?
Thanks in advance
Try this code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Also set
android:windowSoftInputMode="adjustResize"
as property to your Activity in AndroidManifest.xml

Android ScrollView, under Action Bar on Softkeyboard

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

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"

Why does the visibility "gone" for button not work with scrollviews?

I have a layout like:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="1">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:scrollbars="vertical"
android:layout_weight="1">
<-- A relative layout that contains a lot of edit text fields and a few text views at the bottom that cover up the screen-->
</ScrollView>
<Button
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="something"
android:layout_weight="0"
android:visibility="gone"/>
</LinearLayout>
and what i want to do is just achieve the effect that when the keyboard pops up from tapping on any EditView inside the ScrollView, the button at the bottom should NOT cover up any text views, because it is in the gone state. but right now, whenever i tap on any of the EditText fields, it seems to be covering up some of the text views that i have.
why is the screen rendered such that it designates space for the gone button i have at the bottom?
Try adding the following to the activity tag in your manifest.
android:windowSoftInputMode="adjustNothing"

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