Android: How do I prevent the soft keyboard from pushing my view up?
You can simply switch your Activity's windowSoftInputMode
flag to adjustPan
in your AndroidMainfest.xml
file inside your activity tag.
Check the official documentation for more info.
<activity
...
android:windowSoftInputMode="adjustPan">
</activity>
If your container is not changing size, then you likely have the height set to "match parent". If possible, set the parent to "Wrap Content", or a constraint layout with constraingts to top and bottom of parent.
The parent container will shrink to fit the available space, so it is likely that your content should be inside of a scolling view to prevent (depending on the phone manufacturer and the layout choosen...)
- Content being smashed together
- Content hanging off the screen
- Content being inacccessable due to it being underneath the keyboard
even if the layout it is in is a relative or constraint layout, the content could exhibit problems 1-3.
How to prevent soft keyboard from pushing up only the toolbar?
Use a ScrollView.
<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">
<android.support.v7.widget.Toolbar
android:id="@+id/my_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent">
</android.support.v7.widget.Toolbar>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/my_toolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_text1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_text2"/>
...
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/edit_text7"/>
</LinearLayout>
</ScrollView>
Related Topics
How to Create an Object of an Activity in Other Class
Install/Uninstall Apks Programmatically (Packagemanager VS Intents)
How to Check the Current Status of the Gps Receiver
Android Gradle Plugin 0.7.0: "Duplicate Files During Packaging of Apk"
Determining the Size of an Android View At Runtime
What Is the Android Uithread (Ui Thread)
"Failed to Load Ad: 3" With Doubleclick
Difference Between Compilesdkversion and Targetsdkversion
Android Basics: Running Code in the Ui Thread
Android Intent Filter For a Particular File Extension
How to Convert a Base64 String into a Bitmap Image to Show It in a Imageview
How to Hook into the Power Button in Android
Different Values Folders in Android
Dilemma: When to Use Fragments VS Activities:
How to Prevent Custom Views from Losing State Across Screen Orientation Changes
How to Update a Single Row in a Listview