Ich habe eine “Speichern”-Taste, die ich zusammen mit der Soft-Tastatur nach oben drücken möchte. Wenn der Benutzer also in meinem Layout auf einen EditText klickt, muss die Schaltfläche über der Tastatur bleiben. Jetzt wird die Taste unter der Tastatur versteckt. Wie machst Du das?
Danke im Voraus!

oneavi
Zusammen mit der Antwort von Inthathep müssen Sie ein Attribut in der übergeordneten Ansichtsgruppe hinzufügen
android:fitsSystemWindows="true"
um es wie gewünscht zu bearbeiten. dh in der Manifestdatei für die Aktivität add
android:windowSoftInputMode="adjustResize"
und zB.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:fitsSystemWindows="true" <!-- add this -->
android:orientation="vertical"
>
<EditText
android:id="@+id/et_assetview_comment"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="80dp"
android:background="@color/white"
android:hint="Enter comments"
/>
<Button
android:id="@+id/btn_assetview_postcomment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="POST"
/>
</LinearLayout>
Bestellen Sie Ihr Layout so und Sie können die Schaltfläche über der Tastatur platzieren
<?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"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/button_next"
android:background="#0ff"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="250dp"
android:hint="Hint"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABC"
android:textSize="50sp"
/>
</LinearLayout>
</ScrollView>
<Button
android:id="@+id/button_next"
android:layout_width="match_parent"
android:layout_height="60dp"
android:layout_alignParentBottom="true"
android:layout_margin="10dp"
android:text="Button Next"
/>
</RelativeLayout>
Im Android-Manifest
<application
...
>
<activity android:name=".YourActivity"
android:windowSoftInputMode="adjustResize"
>
</activity>
</application>

Beachten Sie, dass statt RelativeLayout
Sie können auch eine andere verwenden ViewGroup
wie LinearLayout
mit Gewicht, CordinatorLayout
…

Nathan O’Kane
Das ist also ein ziemlich alter Beitrag, aber ich hatte Probleme mit den bereitgestellten Antworten. Sowohl oneavi als auch Intahep sind korrekt, aber lassen Sie mich Ihnen genau zeigen, wo die android:windowSoftInputMode="adjustResize"
geht.
im Android-Manifest
<activity android:name=".DataScreen" />
<activity android:name=".PauseScreen" />
<activity android:name=".RouteInfo"
android:windowSoftInputMode="adjustResize"> <!--This goes in the specific activity with the button -->
</activity>
Diese einfache Einrichtung scrollt das gesamte Layout mit der Tastatur nach oben.
<RelativeLayout 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">
<ImageView
android:id="@+id/image_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/recycler_view"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="@drawable/image" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/button"
android:layout_centerHorizontal="true" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Button" />
</RelativeLayout>
Kernpunkte:
- Dem Manifest wurde nichts hinzugefügt.
- Das Bild muss “wrap_content” (keine feste Größe) sein, damit Android die Größe nach Bedarf ändern kann.
- Alle Ansichten müssen wie oben gezeigt verknüpft werden. Die Ansicht von unten layout_alignParentBottom=”true”, die Ansicht von oben layout_alignParentTop=”true” und alle Zwischenansichten layout_above=”@id/view_below”.
- Das Attribut layout_below=”@id/view_above” funktioniert aus irgendeinem Grund nicht.
10105100cookie-checkAndroid: So drücken Sie die Taste über der Soft-Tastaturyes
android-developers.blogspot.com/2009/04/…
– CommonsWare
10. März 2013 um 15:17 Uhr
@CommonsWare Eigentlich ist der Artikel, auf den verwiesen wird, hier keine Hilfe. OP hat eine Schaltfläche unter seinem EditText-Feld (ein gemeinsames Layout). Es gibt eigentlich keine Möglichkeit, den EditText hochzuschieben und der Knopf Verwenden der Standardeinstellungen für die Eingabemethode. Unglücklich.
– David Wasser
10. März 2013 um 15:28 Uhr
@DavidWasser: Dann mache die Aktionsschaltfläche des IME dasselbe wie die versteckte Schaltfläche.
– CommonsWare
10. März 2013 um 15:54 Uhr
@CommonsWare Was ist, wenn es auch ein Kontrollkästchen gibt? Dann hilft die Aktion des IME eigentlich nicht weiter
– Antek
6. Juli 2017 um 8:00 Uhr
Die Antworten auf diese Frage müssen aktualisiert werden, damit sie mit ConstraintLayout funktionieren.
– SMBiggs
19. September 2021 um 18:47 Uhr