3

In my chat app that i'm currently working on, i have a bottom bar with an edit text and this is my layout for the editText :

 <RelativeLayout
    android:id="@+id/bottom_bar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
>

  <EditText
      android:id="@+id/edt_send_message"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:layout_alignParentTop="true"
      android:layout_centerHorizontal="true"
      android:layout_gravity="center_vertical"
      android:layout_marginStart="12dip"
      android:layout_toEndOf="@+id/img_add"
      android:layout_toStartOf="@+id/img_send_message"
      android:background="#00000000"
      android:hint="@string/send_message"
      android:inputType="textCapSentences|textMultiLine|textAutoComplete|textAutoCorrect"
      android:isScrollContainer="false"
      android:lineSpacingMultiplier="1.2"
      android:maxHeight="120dip"
      android:minHeight="45dip"
      android:paddingBottom="19dip"
      android:paddingTop="19dip"
      android:scrollbars="none"
      android:textColorHint="@color/colorPrimary"
      android:textSize="16sp">
  </EditText>

<!-- OTHER STUFF -->

</RelativeLayout>

Its fine when i start typing, multiline kicks in well.

But when i move the focus to the first line this is what happens, part of the edit text moves below the keyboard.

enter image description here

I know using adjustResize will do the trick, but i can't use this since i have a bitmap and it gets compressed. So i can't use adjustResize

Need help, Thanks in advance.

Tejas
  • 437
  • 5
  • 12

2 Answers2

0

Interesting question, only thing I came up with is this hacky solution. Also I am not sure this 200ms would be enough for slower devices. But maybe it will help you.

final EditText txtEdit = (EditText) findViewById(R.id.edt_send_message);
        txtEdit.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View view)
            {
                final int sel = txtEdit.getSelectionStart();
                txtEdit.setSelection(txtEdit.getText().length());
                txtEdit.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        txtEdit.setSelection(sel);
                    }
                }, 200);
            }
        });
SILL
  • 66
  • 5
-1

I think you can find your answer in this page answer but as a common law i copy the solution so that my answer wouldn't lead to just a link.

<!-- Dummy item to prevent AutoCompleteTextView from receiving focus -->
<LinearLayout
    android:focusable="true" 
    android:focusableInTouchMode="true"
    android:layout_width="0px" 
    android:layout_height="0px"/>

<!-- :nextFocusUp and :nextFocusLeft have been set to the id of this component
to prevent the dummy from receiving focus again -->
<AutoCompleteTextView android:id="@+id/autotext"
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:nextFocusUp="@id/autotext" 
    android:nextFocusLeft="@id/autotext"/>

if it doesn't work out, let me know.

Community
  • 1
  • 1
Mehran Zamani
  • 831
  • 9
  • 31