Android keyboard does not override buttons

Asked

Viewed 1,674 times

0

On one of the screens of my application:

inserir a descrição da imagem aqui

When I open the keyboard it overwrites the finished button:

inserir a descrição da imagem aqui

Screen that original Food Registry

inserir a descrição da imagem aqui

Already on this other application screen this does not happen and I would like it to happen:

inserir a descrição da imagem aqui

Follow the code from the last screen:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_registro_alimento"
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"
tools:context="com.example.joao.vitagochi.RegistroAlimentos">

<TextView
    android:text="Refeição"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="16dp"
    android:textSize="16sp"
    android:id="@+id/textView7" />

<Spinner
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textView7"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:spinnerMode="dropdown"
    android:layout_marginBottom="16dp"
    android:id="@+id/spnR" />

<TextView
    android:text="Horario"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/spnR"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="16dp"
    android:textSize="16sp"
    android:id="@+id/textView8" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="time"
    android:maxLength="5"
    android:text="HH:MM"
    android:layout_below="@+id/textView8"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:textSize="16sp"
    android:layout_marginBottom="16dp"
    android:id="@+id/horarioAlimento" />

<TextView
    android:text="Alimento"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/horarioAlimento"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="16dp"
    android:textSize="16sp"
    android:id="@+id/textView9" />

<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="textPersonName"
    android:ems="10"
    android:layout_below="@+id/textView9"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_marginBottom="16dp"
    android:layout_marginRight="16dp"
    android:id="@+id/edtAlm" />

<TextView
    android:text="Quantidade"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView10"
    android:layout_below="@+id/horarioAlimento"
    android:layout_toRightOf="@+id/edtAlm"
    android:layout_marginBottom="16dp"
    android:textSize="16sp"/>


<EditText
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:ems="2"
    android:id="@+id/edtQtd"
    android:layout_below="@+id/textView10"
    android:layout_alignLeft="@+id/textView10"
    android:layout_alignStart="@+id/textView10" />

<Button
    android:text="CONCLUIDO"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:id="@+id/btnConcluidoAlimento" />

<ListView
    android:id="@+id/lv"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="16dp"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_above="@+id/btnAddAlimento"
    android:layout_below="@+id/edtQtd" />

<Button
    android:text="Add Alimento"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/btnAddAlimento"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

Android Manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.joao.vitagochi">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme"
    tools:replace="android:label">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".RegistroAtividades"
        android:label="Registro de Atividades"
        android:parentActivityName=".MainActivity" />
    <activity
        android:name=".RegistroAlimentos"
        android:label="Registro de Alimentos"
        android:parentActivityName=".MainActivity" />
    <activity
        android:name=".RegistroRotina"
        android:label="Registro de Rotina"
        android:parentActivityName=".MainActivity" />
    <activity
        android:name=".Motivacao"
        android:label="Motivação"
        android:parentActivityName=".MainActivity" />
    <activity
        android:name=".Historico"
        android:label="Historico"
        android:parentActivityName=".MainActivity" />
    <activity
        android:name=".Videos"
        android:label="Videos"
        android:parentActivityName=".Motivacao" />
    <activity
        android:name=".Frases"
        android:label="Frases"
        android:parentActivityName=".Motivacao" />
    <activity android:name=".Audios"
        android:parentActivityName=".Motivacao"
        android:label="Audios"
    />
</application>

  • Shows your Androidmanifest?

  • I edited the post now this with the manifest

2 answers

2

In the Manifest add the following configuration of Activity:

android:windowSoftInputMode="adjustPan"

The android:windowSoftInputMode is responsible for the form of interaction of the main window of the activity with the window containing the software keyboard on the screen. Setting the value of this attribute to adjustPan, the main window of the activity is not resized to create space for the software keyboard on the screen. Instead, you move the contents of the window automatically so that the current focus is never overlaid by the keyboard and users can always see what they type. Typically, this behavior is less desirable than resizing, as the user may need to close the software keyboard to access and interact with the overlapping parts of the window.

Reference: Developer.android.com

0

One solution is you use the ScrollView. With it you can drag the screen so that you can see hidden elements below the keyboard. It is usually used when you have several views on the same screen. See an example:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <!-- coloque todo seu código aqui dentro -->

    </LinearLayout>
</ScrollView>

For more details, see the documentation.

Another option would be for you to insert your button into your Toolbar, but if you have many views you will fall into the same situation.

  • sorry for the delay friend, but I don’t want to see what’s underneath, I just want the keyboard to override the button there after q the person finish typing and summarize the keyboard she can give complete.

  • @Joãocarlos So I really didn’t understand what I meant. Even though I still don’t understand with this comment. It’s not very clear.

  • @Joãocarlos you want your button to be aligned at the bottom of your layout is this?

  • I showed in the pictures, but here’s the thing, when I open the keyboard the 2 buttons go up and stand above the keyboard, blocking the q the person is typing in the Food field, so I wanted when the keyboard was triggered it overlapped the 2 buttons thus leaving the field Food fully visible.

  • I added another image of the screen, of a look, I think you will understand.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.