I'm not sure what title should I put in here but here is the question.
I want my fields to be attached to the bottom of the screen when keyboard is out.
When there is no keyboard, I want my fields to be at the center of the screen.
Basically 1 and 2 are spaces and I want Space I to be first candidate on squeezing when keyboard is out.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
<android.support.design.widget.TextInputLayout
android:id="#+id/walletPasswordEditLayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp">
<android.support.design.widget.TextInputEditText
style="#style/AppEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>
<Button
style="#style/AppButton.Black"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="16dp"
android:layout_marginStart="16dp"
android:text="#string/unlock_button"/>
<android.support.v4.widget.Space
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>
</LinearLayout>
</FrameLayout>
add this in your activity
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
Please check this Link:
You can add in your menifest for the activity you want to prevent such issue. Also make sure if you are having a bit more content use scrollView as a parent. And soft input mode as "adjustResize"
android:windowSoftInputMode="adjustResize"
or
android:windowSoftInputMode="adjustPan"
Related
I have a multi-line editText inside a scrollView follow by a button.
If using adjustPan, the softkeyboard cover up the whole editText, leaving only the first line.
When using adjustResize, even the button shows up which is worst
Here is my xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
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="match_parent">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="#id/btn_save">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="600dp"
android:background="#color/LightBlue"/>
<androidx.appcompat.widget.AppCompatEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text"
android:inputType="textMultiLine"
android:singleLine="false"
android:gravity="top"
android:minLines="8" />
</LinearLayout>
</ScrollView>
<com.google.android.material.button.MaterialButton
android:id="#+id/btn_save"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Save"
android:clickable="false"
app:backgroundTint="#color/gray_jll"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
What I want (temporarily achived using gravity bottom, but of course we want the text to display on the top using gravity top)
I looked at Android soft keyboard covers EditText field.
But I am not using full screen mode.
android:isScrollContainer="true" does nothing.
Please tell me what is causing this. Thanks in advance.
I want to move only edittext when keyboard will appear.
Here is my XML codes.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".chat.MultipleMediaActivity">
<androidx.viewpager.widget.ViewPager
android:id="#+id/multiple_media_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginStart="0dp"
android:layout_marginTop="0dp" />
<include
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginTop="40dp"
layout="#layout/multiple_media_custom_toolbar" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#drawable/multimedia_edittext_bg_ca"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:orientation="horizontal"
android:layout_marginBottom="5dp">
<ImageView
android:id="#+id/emoj_button"
android:layout_width="24dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="13dp"
android:src="#drawable/main_emoj_ca"
android:tag="emoji" />
<com.vanniktech.emoji.EmojiEditText
android:id="#+id/multiple_media_text_message"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/AppTrasColor"
android:hint="#string/write_message_ca"
android:inputType="textCapSentences|textMultiLine"
android:maxLines="4"
android:minHeight="50dp"
android:textColor="#color/AppFirstTextColorDark"
android:textColorHint="#color/AppDullTextColor"
android:textSize="#dimen/Text17"
tools:ignore="LabelFor"
android:layout_marginStart="10dp"/>
</LinearLayout>
<androidx.recyclerview.widget.RecyclerView
android:id="#+id/multiple_media_preview"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp">
</androidx.recyclerview.widget.RecyclerView>
</LinearLayout>
</RelativeLayout>
What I have tried
in manifest
android:windowSoftInputMode="adjustPan"
When edittext getting focus, edittext stay below the keyboard,
I want to setup like
Bottom line of edittext and Top line of keyboard will be the same. It means edittext will always stay above the keyboard when it appear.
You can't. Android has 3 modes for when the keyboard appears:
adjustNone- do nothing. The keyboard will appear over the app as it is. This is almost never used
adjustResize- the keyboard is asked for its height, and the app is fit into the remaining screen. This will cause elements to be relaid out.
adjustPan- the app will scroll such that the cursor is on screen. If this is a multiline edit box, it promises that the line with the cursor will be shown. Other lines below it may or may not be, depending on where on the screen that cursor is.
There is no mode for moving the entire edit text above the keyboard.
I have some problem in my layout width edit-text
here are screenshots which describe my problem
1. normal layout (all views are inside the LinearLayout)
2. I want layout below when user input many text lines inside the Edit Text
3. But When user enter many text lines.. my layout looks like below.
I want the Edit Text should be stretched until only ImageView meets the bottom ViewGroup.
but, more entering text lines, more being increased the height of Edit Text so, i cannot see Image View.
i'd appreciate it if you give me any solution.
LinearLayout handles this sort of layouts great. You can use the attribute android:layout_weight="1" within a LinearLayout to set the priority of the space you want the object to take.
The official documentation describe it best:
developer.android.com
Take RelativeLayout as your parent layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="?actionBarSize"
android:orientation="vertical">
<EditText
android:id="#+id/editText1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:inputType="textMultiLine"
android:scrollbars="vertical"/>
<ImageView
android:id="#+id/imageView1"
android:layout_marginBottom="?actionBarSize"
android:layout_width="match_parent"
android:layout_weight="0.1"
android:layout_height="?actionBarSize" />
</LinearLayout>
<View
android:id="#+id/view1"
android:layout_width="match_parent"
android:layout_height="?actionBarSize"
android:layout_alignParentBottom="true" />
<?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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/bottomGroup"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout
android:id="#+id/bottomGroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
</RelativeLayout>
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
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.