I have the following layout for an activity...
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MainActivity"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ScrollView
android:id="#+id/scroll_view"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:scrollbars="vertical"
android:fillViewport="true"
android:background="#3ba4a4a4"
android:fadeScrollbars="true">
<TextView
android:id="#+id/text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textIsSelectable="false"
android:text="#string/test_text"
android:textSize="40sp"/>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="2dp">
<EditText
android:id="#+id/edit_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:hint="#string/edit_text_hint"
android:layout_marginTop="8dp"
android:theme="#style/InputMethodTheme"/>
<ImageButton
android:id="#+id/button_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_action_send"/>
</LinearLayout>
When the soft keyboard is opening I want the end of the TextView to go up with the EditText...
Any Idea on How to do That?
The EditText is going up normally as it should but its blocking the text view
i have tried the following in the manifest file in my activity
android:windowSoftInputMode="adjustPan"
But the action bar disappears which i don't want...
UPDATE
I tried the following in the TextView
android:layout_gravity="bottom"
and it seems to react as i want it to but some of the
lines before it are getting removed and extra spaces are
being added after the last word...
Basically you need to listen to the keyboard opening event.
More How to capture the "virtual keyboard show/hide" event in Android?
Be careful when dealing with devices with soft navigation buttons e.g., Nexus 5, you may need to take the navigation bar height into consideration.
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 am trying to copy whatsapps UI for sending pictures, it opens a screen with a keyboard and a textfield at the bottom.
I have a relative layout with a textinputfield at the bottom. The relative layout has a background image. If the user clicks on the textinputfield the textinputfield must stay visible above the keyboard however the Relative layout background image needs to not resize.
Currently my layout looks like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/cover"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#drawable/newbg"
android:orientation="vertical"
>
<LinearLayout
android:layout_alignParentBottom="true"
android:id="#+id/chatFooter"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ECEFF1"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/sendLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:weightSum="2"
android:paddingTop="#dimen/scale_5dp"
android:paddingBottom="#dimen/scale_5dp">
<LinearLayout
android:layout_width='0dp'
android:layout_height="wrap_content"
android:layout_weight="1.8">
<com.heyjude.heyjudeapp.customview.EditRobotoRegular
android:id="#+id/editChatMsg"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:background="#drawable/linear_back"
android:hint="Add a message..."
android:padding="#dimen/scale_5dp"
android:inputType="textMultiLine|textCapSentences|text"
android:textColor="#5f6060"
android:textColorHint="#5f6060"
android:textSize="#dimen/text_14"
android:imeOptions="actionSend"
/>
</LinearLayout>
<ImageView
android:id="#+id/ivSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_chat_icon"
android:layout_weight="0.3" />
</LinearLayout>
</LinearLayout>
And i have android:windowSoftInputMode="adjustResize|stateHidden"
Which is working great for the inputfield moving up above the keyboard, but the background image is distorting horribly.
Thanks for any help!
Here is how it looks on whatsapp which is what i want to recreate
Here is the keyboard down
and here is keyboard up
I have a difficulty with implementing scroll view while using Theme.Black.NoTitleBar.Fullscreen.
When the user opens the application and click on editText the keyboard opens but the user cannot scroll beneath the edittext.
After many attempts I figured it something to do with the theme I am using (fullscreen)
This is my code .xml:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="false"
android:fillViewport="true"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:id="#+id/vieww"
android:layout_width="match_parent"
android:layout_height="1000dp"
android:background="#android:color/holo_green_dark" />
<EditText
android:id="#+id/test_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/vieww" />
<View
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#id/test_edit"
android:background="#android:color/holo_blue_bright" />
</RelativeLayout>
When the keyboard is opened the user cannot see the lowest view beneath the edittext.
What I tried so far:
I played a lot with windowSoftInputMode of the activity I tried combination of adjustResize/adjustPan but nothing seems to work.
I tried to change the container to LinearLayout but it still not working for me
I found a solution here here
The problem with this solution I need to change the minSdk to 19, when the application starts I can see black stripe where has been the title bar.
the other issue is when the user open the keyboard by pressing on edittext the title bar returns
I think you should put the ScrollView in a Relative Layout, so you can fit the size, if the keyboard appears.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fadeScrollbars="false"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<View
android:id="#+id/vieww"
android:layout_width="match_parent"
android:layout_height="1000dp"
android:background="#android:color/holo_green_dark" />
<EditText
android:id="#+id/test_edit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/vieww" />
<View
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_below="#id/test_edit"
android:background="#android:color/holo_blue_bright" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I'm using a custom keyboard with keyboardview.
The keyboard is in the xml of the activity, as you can see here:
<LinearLayout 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"
android:orientation="vertical" >
<EditText
android:id="#+id/edittextOne"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#3498db"
android:layout_weight="1"
android:gravity="bottom"
android:orientation="vertical" >
<ImageView
android:layout_width="match_parent"
android:layout_height="18dp"
android:background="#9b59b6" />
</LinearLayout>
<android.inputmethodservice.KeyboardView
android:id="#+id/keyboardview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:focusableInTouchMode="true"
android:visibility="visible" />
</LinearLayout>
When the user uses the back button on the device keyboard disappears, as is normal.
My question is: How can I make impossible to hide the keyboard?
My intention is ALWAYS visible.
I tried android: windowSoftInputMode = "stateAlwaysVisible" but does not work.
Thank you!
Try this in your keyboard class. The onWindowHidden method get called if you press back button or the keyboard disappear for other reasons.
#Override
public void onWindowHidden()
{
//Nothing
super.onWindowHidden();
}