How to set layout above soft keyboard - android

I have next xml layout
<ScrollView
android:id="#+id/transfer_scroller"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue_500"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:orientation="vertical" ></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="400dp"
android:orientation="vertical" ></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="#+id/tv_money_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:textColor="#color/gray_400">
</EditText>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:background="#android:color/transparent"
android:text="#string/btn_transfer_select_receiver"
android:textColor="#color/blue_500" />
</LinearLayout>
</LinearLayout>
when i scroll down and click on editText - open softKeyBoard and layout resize, so i can see only editText field, and I need all last LinearLayout was above keyboard so user can see btn below editText.
here is my activity in manifest:
<activity
android:name=".acitivity.Activity"
android:label="#string/title_activity"
android:theme="#style/AppTheme.NoActionBar"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan|stateVisible">
</activity>
i was trying to set android:windowSoftInputMode="adjustResize" but it looks like it doesn't work with scrollView...
any idea how to fix this?

1) In AndroidManifest.xml use:
android:windowSoftInputMode="adjustResize"
2) Check this one...
3) Or you can try this one:
android:windowSoftInputMode="adjustResize|stateVisible"
If you need to open KeyBoard originally.
Hope it helps you.

Related

Text Editor keyboard overlaps with the recyclerview list

The layout has a recyclerview and a text editor at the bottom of the view. When I click the editor, the keyboard popup and overlaps with the recycerview. I want the recyclerview to be resized when the keyboard is brought up. In my Manifest file I have :
<activity android:name=".CommentActivity"
android:label="yourtime"
android:windowSoftInputMode="adjustResize">
</activity>
My layout looks like this :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:orientation="horizontal"
android:minWidth="25px"
android:minHeight="25px"
android:id="#+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="100"
android:layout_alignParentBottom="true">
<EditText
android:inputType="textMultiLine"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="85"
android:id="#+id/commenteditor"
android:hint="Write a comment" />
<ImageButton
android:src="#drawable/arrow"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="15"
android:id="#+id/send"
android:background="#ffff" />
</LinearLayout>
How do I make the list scroll up or get resized when the keyboard comes up? I have tried encapsulate the recyclerview inside scrollview but that didn't work.
This is what it looks like:
I want it to look like this:
What should I do?
In your
<activity android:name=".CommentActivity"
android:label="yourtime"
android:windowSoftInputMode="adjustResize|adjustPan">
</activity>
You cannot have more than one of
adjustResize|adjustPan
the results for this are undefined.
In your case, the one you want is
<activity android:name=".CommentActivity"
android:label="yourtime"
android:windowSoftInputMode="adjustResize"/>
You can read more about this here:
activity-element
in the section that covers android:windowSoftInputMode
You should also adjust your layout so the recycler view is above the edit text container.
<android.support.v7.widget.RecyclerView
android:id="#+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/linearLayout1"/>

Android - How to adjust a popup when the soft keyboard shows up

I want to replicate this effect in my layout. But in my layout when the keyboard show up, my pop-up is not adjusted.
The device adjust me the main activity below and not the popup.
this is my popup layout.xml :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/sfondo_semi_trasparente_scuro">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="#color/white"
android:orientation="vertical">
<EditText
android:id="#+id/textNomeGiocatoreNewTeam"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:hint="Nome giocatore"/>
<EditText
android:id="#+id/textNumeroMagliaGiocatoreNewTeam"
android:inputType="number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Numero Maglia"/>
<Button
android:id="#+id/buttonConfirmAddNewPlayer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Aggiungi giocatore"
android:layout_gravity="center"/>
</LinearLayout>
Can someone help me?
Try instead this:popupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
You can also add this to your AndroidManifest.xml
<activity
...
android:windowSoftInputMode="adjustResize"
</activity>

Android full screen, EditText pushes other view up

I am working on an app and have a problem.
I have an vieww like the image below with an image and an edittext field the right position. But when i click on the edittext field and it gets the focus it pushes the other view up.
I have the full screen flag and if i dont use that it works perfect and the image keeps theire position and dont pushed up. I need that with full screen flag.
Is there someone who have some example or can help me. I have used the 'windowSoftInputMode' with all the posibles values.
Here my layout code and examples how it now works and how it needs to be.
xml layout source:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical|none" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- layout for images -->
<RelativeLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/image"
android:contentDescription="TODO"/>
</RelativeLayout>
<!-- layout for edit text -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_alignTop="#id/imageview"
>
<EditText
android:id="#+id/tekstbox"
android:imeOptions="flagNoExtractUi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Here is the image how i start in the activity
When i click in the edittext field i want my view to react as below:
But when the edittext gots focus it pushes everything up like below:
Does someone know how to solve this with the fullscreen flag on?
Thanks.
User this line of code in your Manifest.xml. In the activity where the problem is occuring
<activity
android:windowSoftInputMode="stateVisible|adjustNothing">
</activity>
Add the below line in your manifest file in activity tag:
android:windowSoftInputMode="adjustResize"
and add ScrollView in your layout file like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:fillViewport="true"
android:orientation="vertical"
android:scrollbarStyle="insideOverlay"
android:scrollbars="vertical|none" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<!-- layout for images -->
<RelativeLayout
android:id="#+id/imageview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top" >
<ImageView
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/image"
android:contentDescription="TODO"/>
</RelativeLayout>
<!-- layout for edit text -->
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:gravity="bottom"
android:layout_alignTop="#id/imageview"
>
<EditText
android:id="#+id/tekstbox"
android:imeOptions="flagNoExtractUi"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text" />
</RelativeLayout>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Add the below line in your manifest file in activity tag:
android:windowSoftInputMode="adjustPan|stateHidden"

how to make an android view scrollable when the keyboard appears?

I have a view with some fields (name, email, password, register button) :
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="#+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
//Layouts
</ViewFlipper>
</ScrollView>
When I focus an edittext field, the keyboard appears and is overlaying the lower fields on the view. So I can't see them when the keyboard is present. I would like to know how to make the view scrollable so that I can see the lower fields. And additionally, how to make the view scroll automatically to make the focused field visible.
You need to include android:windowSoftInputMode="adjustResize" attribute for your activity in the AndroidManifest.xml file - and then Android should do the resizing for you automatically:
<activity android:name="..."
...
android:windowSoftInputMode="adjustResize">
...
/>
I have created simple xml file.
step 1. you can scroll when key-pad is appeared.
step 2. when you click on Text-Field it will come on Focus/above keypad.
<ScrollView android:id="#+id/ScrollView01"
xmlns:android="http://schemas.android.com/apk/res/android"
android:fillViewport="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:weightSum="1.0"
android:layout_height="match_parent"
android:focusable="true"
android:focusableInTouchMode="true"
android:id="#+id/l_layout">
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/editText1"
android:layout_marginTop="100dp">
<requestFocus></requestFocus>
</EditText>
<EditText
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:id="#+id/editText2"
android:layout_marginTop="100dp">
</EditText>
</LinearLayout>
</ScrollView>
In my case #Aleks G solution was not working. so I resolved my problem with
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/registration_scroll_view"
android:layout_alignParentTop="true"
android:layout_above="#+id/btn_register_submit"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<!--This comment will be replaced
by your focusable views-->
</LinearLayout>
</ScrollView>
<Button
android:id="#+id/btn_register_submit"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:background="#drawable/form_action_button_green"
android:gravity="center"
android:text="#string/submit"
/>
</RelativeLayout>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ViewFlipper
android:id="#+id/viewflipper"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/scroll_container">
//Layouts
</ScrollView>
</ViewFlipper>

Use scrollview and adjustPan together android

In my manifest I have written
<activity android:name=".email"
android:label="#string/app_name"
android:theme="#android:style/Theme.NoTitleBar"
android:windowSoftInputMode="adjustPan">
</activity>
And in my layout I have written
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white" >
<ImageView
android:id="#+id/bottomImage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/ic_backdrop_wave" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dip"
android:isScrollContainer="false" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText>
</EditText>
<EditText>
</EditText>
<EditText>
</EditText>
</LinearLayout>
</ScrollView>
So, When I clicked on any edit text it will not re sizes the imageview but It will also disable scroll view.
Now what I have to do to come out, I want such layout in which height of image view will not change and it will stick to align parent bottom while any soft keyboard is open, and scroll view is enable while soft key board is open.
Did you tried using
android:windowSoftInputMode="adjustResize"
This will not resize the imageview, instead it will auto adjust the screen when the keyboard popup
Here is the solution.
Make sure your Image is inside the single child inside ScrollView aligned to bottom, like this.
<ScrollView
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_width="match_parent"
android:fillViewport="true"
android:isScrollContainer="true"
android:layout_height="0dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
....
....
<androidx.appcompat.widget.AppCompatImageView
android:id="#+id/bottom_illustration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="#+id/some_text_view"
app:layout_constraintVertical_bias="1.0"
app:srcCompat="#drawable/login_illustration" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
Add the following properties to ScrollView
android:fillViewport="true"
android:isScrollContainer="true"
Add this to under your activity tag in AndroidManifest.xml
android:windowSoftInputMode="adjustResize"

Categories

Resources