-1

I have seen a few similar questions, but they want the things to show up, I want to hide them. Basically I have a bunch of elements in my RelativeLayout and when the activity shows, the keyboard pops up, since I have an editText, and the elements that are aligned in the Bottom go up along the keyboard, I don't want that, I want them to stay hidden, any idea how can I achieve this? This is the xml of my Activity:

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@drawable/bg"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:orientation="vertical"
    android:id="@+id/invoices_layout"
    tools:context=".NavManager">

    <RelativeLayout
        android:id="@+id/mcr_bar_progress"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true"
        android:visibility="visible">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:layout_centerInParent="true"
            android:layout_marginTop="15dp"
            android:text="Agregar Productos"
            android:textColor="@android:color/white"
            android:textSize="34sp" />

        <TextView
            android:id="@+id/textGrid2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/textView"
            android:layout_centerHorizontal="true"
            android:layout_marginTop="0dp"
            android:text="Grupo MkTech Solutions"
            android:textColor="@android:color/white"
            android:textSize="15sp" />

        <EditText
            android:id="@+id/txtproducto"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:layout_alignParentEnd="true"
            android:layout_marginStart="0dp"
            android:layout_marginTop="92dp"
            android:layout_marginEnd="0dp"
            android:hint="Ej: Refresco Natural"
            android:inputType="text"
            android:textColor="@color/white"
            android:textSize="15sp"
            app:backgroundTint="@color/white" />

        <ImageButton
            android:id="@+id/btnbuscar"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignTop="@+id/txtproducto"
            android:layout_alignEnd="@+id/txtproducto"
            android:layout_marginTop="4dp"
            android:layout_marginEnd="0dp"
            android:onClick="onClickSwitch"
            app:srcCompat="@drawable/research" />

        <TextView
            android:id="@+id/txttotal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:padding="10dp"
            android:textColor="@color/WhiteBgText"
            android:textSize="15sp" />

        <ImageButton
            android:id="@+id/btnlimpiarcarro"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentLeft="true"
            android:onClick="onClickCleanCart"
            android:padding="10dp"
            app:srcCompat="@drawable/quit" />

        <ScrollView
            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="150dp"
            android:layout_marginBottom="50dp"
            android:fillViewport="true">

            <TableLayout
                android:id="@+id/tableInvoices"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:padding="0dp"
                android:stretchColumns="*"></TableLayout>

        </ScrollView>

    </RelativeLayout>

</LinearLayout>

The last two elements before the scrollview are the ones that need to stay hidden.

  • 1
    you could call `view.setVisibility(View.GONE);` on the views that you want to hide, you should look for a way to trigger this method when keyboard is shown check https://stackoverflow.com/questions/4312319/how-to-capture-the-virtual-keyboard-show-hide-event-in-android – Omar Mneimneh Nov 07 '18 at 15:51
  • 1
    If I understood the problem correctly, a simple solution would be to call on the elements `setVisibility(View.GONE)` when the keyboard shows up. – Susmit Agrawal Nov 07 '18 at 15:51

2 Answers2

1

add the following to your activity in the manifest:

android:windowSoftInputMode="adjustPan"

from the API:

The activity's main window is not resized to make room for the soft keyboard. Rather, the contents of the window are automatically panned so that the current focus is never obscured by the keyboard and users can always see what they are typing. This is generally less desirable than resizing, because the user may need to close the soft keyboard to get at and interact with obscured parts of the window.

Nikos Hidalgo
  • 3,666
  • 9
  • 25
  • 39
  • This would not actually hide the views but it's going to adjust the view so the focused EditText is above the keyboard. But maybe could solve the problem. – Omar Mneimneh Nov 07 '18 at 15:56
  • 1
    @OmarMneimneh depending on the layout and how many views there are available, it could work. However, I understand that is not always the case. – Nikos Hidalgo Nov 07 '18 at 15:59
1

By my understanding of your question you do not want the keyboard to push the UI elements at the bottom of your layout.

To achieve this all you need to do is put the following line into your manifest activity tag:

android:windowSoftInputMode="adjustNothing"
Nejc Fosnaric
  • 51
  • 1
  • 7