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>
Soft keyboard pushing layout
Remove your Background image in xml file
Set Background image in java file using below code:
getWindow().setBackgroundDrawable(ContextCompat.getDrawable(this, R.drawable.banner1));
Related Topics
Static Variable Null When Returning to the App
Do X86 Android Avd's Work on Linux on Amd
Media Queries Not Behaving as Expected on Android
How to Reference Style Attributes from a Drawable
Android 5.0 Android:Elevation Works for View, But Not Button
Android Get Image from Gallery into Imageview
Cannot Load Library: Reloc_Library[1285]: Cannot Locate 'Rand'
How to Programmatically Turn Off Wifi on Android Device
Android Support Repo 46.0.0 with Android Studio 2.3
Listview Subobject Clickable Confilct
How to Change Color of Textinputlayout's Label and Edittext Underline Android
How to Handle Imeoptions' Done Button Click
Convert Content:// Uri to Actual Path in Android 4.4
Accessing Sharedpreferences Through Static Methods