soft keyboard covers edittexts, scroll view doesnt work - android

I have few editText in ScrollView. If there are many editTexts, and they exceed the display, everything works fine, but if they doesnt, and soft keyboard is opened, I cant scroll it(keyboard covers few of them). My layout:
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
<EditText
android:layout_width="200dp"
android:layout_height="wrap_content"
/>
</LinearLayout>
</ScrollView>
Any suggestions?

I added this field in the ScrollView tag:
android:isScrollContainer="false"

You can use windowSoftInputMode attribute for your activity and set it to "adjustResize". This will make room for your soft keyboard.
<activity android:windowSoftInputMode="adjustResize" />

You may need to change the "windowSoftInputMode" for the activity in your manifest file:
android:windowSoftInputMode="adjustResize"
I would try that.

Related

Android Soft keyboard float only specific layout

I have a layout, code below
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->
<LinearLayout
android:id="#+id/layout1"
android:layout_alignParentBottom="true"
android:layout_above="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitStart"
android:layout_marginLeft="5dp"
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:src="#drawable/ic_menu_send"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
In the above code when keyboard is show i want layout2 to stay in the bottom and layout1 to go up with keyboard. if i add android:windowSoftInputMode="adjustPan|adjustResize" both layout stay in bottom. please help
as you can say this is not work
android:windowSoftInputMode="adjustPan|adjustResize"
just change it this
android:windowSoftInputMode="stateHidden"
and one more thing in your below layout
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<!--some stuff here-->
<LinearLayout
android:id="#+id/layout1"
android:layout_alignParentBottom="true"
android:layout_above="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5"
/>
<ImageButton
android:layout_width="50dp"
android:layout_height="50dp"
android:scaleType="fitStart"
android:layout_marginLeft="5dp"
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:src="#drawable/ic_menu_send"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layout2"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#color/colorPrimary">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
Keep in Mind :
When you have applied this property android:layout_above="#+id/layout2" to layout1 of your LinearLayout then remove this property android:layout_alignParentBottom="true" you don't require it.
So Now that look like this
<LinearLayout
android:id="#+id/layout1"
android:layout_above="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
Note : I am giving background color and specific height to
LinearLayout 2 for your Understandment.
Output :
Normal Screen
KeyBoard Open Screen.
ImProve :
see the upper Image I make Red Mark that property create the problem otherwise every thing is work fine.
Please use this, and tell me if you find any difficulties
<?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">
<!--some stuff here-->
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/layout2"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="5" />
<ImageButton
style="#style/Base.Widget.AppCompat.Button.Borderless"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="5dp"
android:scaleType="fitStart"
android:src="#drawable/ic_menu_send" />
</LinearLayout>
</ScrollView>
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<!--some stuff here-->
</LinearLayout>
</RelativeLayout>
Use different themes for both the layouts.
such as:
One theme refers to adjustPan for windowSoftInputMode attribute.
and another theme refers to adjustResize for windowSoftInputMode attribute.
The fastest way is hide the layouts when soft keyboard is enable and show them again when the soft keyboard is disabled (layout2 on the xml)
Remove this Line as well
android:windowSoftInputMode="adjustPan|adjustResize"
it will work , this is just a simple way , I'm still searching for you
put this line in your manifest file.
android:windowSoftInputMode="stateHidden"
Remove the android:windowSoftInputMode="adjustPan|adjustResize"
And then Hide the layout2 programmatically when soft keyboard open. When soft keyboard close, again make the layout2 visible.
This will give user an experience exactly you want.I'm not shure there is any other way. But Keep searching. good Luck

Layout is getting pushed up

I have a very simple layout that i designed to achieve the tool bar at the top of the screen. I am using weights here to fit all devices. Giving like 11 to the tool bar and 89 to the content body. That will fit all screens no matter what.
Problem:
I have a scroll view inside the content body and inside that scroll view i have like 4 EditText views. When i click the last EditText to type into it my layout gets pushed up specially the tool bar for which i have to use weights.
Now please don't tell me not to use weights, just tell me how can i fix it. how can i stop the layout pushing up? Just like Gmail Client. when you are typing the header is not pushed up, stays there that you can save or send the email.
Main.xml:
<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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/header"
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ffe234"
android:layout_weight="11" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:text="Memories" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="89" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="6"
android:ems="10" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
In your manifest you want you add edit or add the android:windowSoftInputMode. Then set it to adjustNothing, if you don't want the screen to adjust.
<activity
android:name=".MainActivity"
android:label="#string/app_name"
android:windowSoftInputMode="adjustPan|adjustNothing">
</activity>
Documentation
android:windowSoftInputMode
http://developer.android.com/guide/topics/manifest/activity-element.html
adjustNothing 0x30 Don't resize or pan the window to make room for the soft input area; the window is never adjusted for it.
http://developer.android.com/reference/android/R.attr.html#windowSoftInputMode
Please use weight ="0.11" and weight ="0.89"
instead of
weight ="11" amd weight ="89" in your layout.
The layout is pushing up because scroll view adjusts to the entire screen when input method appears.
Try using ScrollView's property isScrollContainer by setting it to false.
It should look like the following:
...
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:isScrollContainer="false" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:minLines="6"
android:ems="10" />
</LinearLayout>
</ScrollView>
...
If this does not help consider setting proper windowSofInputMode in your activity in AndroidManifest.xml.

EditText is not clickable inside a fragment

I have a "has_groups_fragment" fragment, and it has an EditText element.
When I try to click on it, the keyboard is not responding.
the layout is the following:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/has_groups"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ft_background"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/searchGroupsArea"
android:layout_width="350dp"
android:layout_height="wrap_content" >
<EditText
android:id="#+id/inputGroupSearch"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_weight="0.86"
android:clickable="true"
android:ems="10"
android:hint="Search a group..."
android:inputType="textVisiblePassword"
android:textIsSelectable="true" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/magnifyingGlass"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:src="#drawable/search_icon" />
</LinearLayout>
<ListView
android:id="#+id/groupsList"
android:layout_width="fill_parent"
android:layout_height="407dp"
android:layout_weight="1.52"
android:choiceMode="singleChoice" />
</LinearLayout>
Any advices?
Thanks a lot!
I believe the following attribute is the problem:
android:textIsSelectable="true"
When this is set to true for an EditText View, it allows text in the EditText to be selected, but it disallows editing of the text, which is why the keyboard doesn't show.
If you just want to allow normal copy/paste procedures, you don't need to set this.
I think you might have forgotten to add this to your activity, in your AndroidManifest.xml file:
<activity android:name="your_activity_name"
...
android:windowSoftInputMode="adjustPan"
...>
More information
Try removing both android:clickable and android:textIsSelectable attributes

Android, prevent button aligned at bottom in relative layout from going up when doing input in edittext

I have created a relative layout with 3 listviews. At top I have a editText field. In the middle there is a scrollview that fills upp all left-over space. At the bottom I have placed a button. The thing is, when I do an input in the editText field, the keyboard shows up and then the button is moved and placed ontop of the keyboard. It seems like the button allways sticks to the bottom of the view that is "left", but I want it to remain at the bottom of the original window.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/ll_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
>
<TextView
android:id="#+id/tv_course_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/text_view_course_name"
android:textStyle="bold" />
<EditText
android:id="#+id/et_course_name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_save_course_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="saveCourse"
android:text="#string/button_save_course" />
</LinearLayout>
<LinearLayout
android:id="#+id/ll_course_table"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/ll_save_course_button"
android:layout_below="#id/ll_name" >
</LinearLayout>
</RelativeLayout>
Inside your manifest file,
<activity
android:name=".HomeActivity"
android:windowSoftInputMode="stateHidden|adjustPan" >
NOTE:
here,I have used HomeActivity,you need to specify the activity name in which you are setting the above layout xml file.
Try this:
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="saveCourse"
android:gravity="bottom"
android:text="#string/button_save_course" />
or use this
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);

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