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.
Related
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'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"
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 specific question concerning the use of the MaterialSpinner view.
I want the spinner to be perfectly aligned to the right of an EditText wrapped in a android.support.design.widget.TextInputLayout view group for floating label support.
I've tried both LinearLayout and RelativeLayout (using the align to layout attributes) and none are working properly.
I end up with something looking like this.
Below is my layout so far:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<android.support.design.widget.TextInputLayout
android:id="#+id/weightWidget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<EditText
android:id="#+id/weight"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:ems="10"
android:hint="#string/weight"
android:inputType="number" />
</android.support.design.widget.TextInputLayout>
<fr.ganfra.materialspinner.MaterialSpinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/weights_unit_array"
app:ms_alignLabels="false"
app:ms_arrowColor="#0000FF"
app:ms_arrowSize="16dp"
app:ms_floatingLabelColor="#00FF00"
app:ms_floatingLabelText="floating label"
app:ms_hint="#string/unit"
app:ms_multiline="false"
app:spinnerMode="dialog" />
</LinearLayout>
</LinearLayout>
In the preview of the layout designer in Android Studio, it seems that it's aligned but when I run it either on the emulator or a real device, the views are not aligned as shown in the previous screenshot.
I decided not to use the MaterialSpinner view although it looks good with the floating label.
I'm using a regular Spinner with the .underline style applied:
<Spinner
android:id="#+id/height_unit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:entries="#array/heights_unit_array"
android:prompt="#string/unit"
android:spinnerMode="dialog"
style="#style/Widget.AppCompat.Spinner.Underlined"
android:layout_gravity="bottom"/>
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.