Space between keyboard and EditText in Android
Solution 1
I applied above methods which worked for me was Set android:windowSoftInputMode on the Activity to "adjustPan" than i added the padding to the edittext with gravity bottom and it works like charm. Thanks,
Solution 2
May this help you:
If this line is written in your code then remove it:
getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
OR:
You should not be setting your layout_width
and layout_heights
with explicit pixel values. Instead, use wrap_parent
or fill_parent
as appropriate.
OR:
If you have set your minSdkVersion
to 3
then change it to minSdkVersion=4
Edit:
Set android:windowSoftInputMode on the Activity to "adjustPan"
OR:
Add this code in your main activity in setOnTouchListener()
of your EditText
:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_UNSPECIFIED);
Solution 3
Why don't you try this?
android:windowSoftInputMode="adjustResize"
I know you want to adjust pan but this would solve your problem aswell.
Since you really want to stay with adjustPan, maybe you can try re-designing the XML layout a little bit.
You must also add your required padding to the outer most container element in the layout file.
Solution 4
Simple padding in edit text won't work.
Use drawable with your edit text like below:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="8dp"
android:left="8dp"
android:right="8dp"
android:top="8dp">
<shape android:shape="rectangle">
<corners android:radius="10dp" />
<stroke
android:width="1dp"
android:color="@color/white" />
<solid android:color="@color/transparent" />
</shape>
</item>
</layer-list>
and then use
android:windowSoftInputMode="adjustPan"
in your manifest file.
Altynbek Usenbekov
Updated on July 17, 2022Comments
-
Altynbek Usenbekov almost 2 years
Soft input mode is
"SOFT_INPUT_ADJUST_PAN"
, and when keyboard shown,EditText
moves up to stay visible, but the keyboard and txt's bottom are always sticked together as seen on screenshot, I want some space between them, is it possible?Also input mode must stay as
"SOFT_INPUT_ADJUST_PAN"
.Sorry form my english, Thanks in Advance...
-
Altynbek Usenbekov almost 11 yearsThank you, input mode must stay SOFT_INPUT_ADJUST_PAN. When keyboard shown it sticks to edittexts(for example edittext at bottom of screen). It is ok but I want some space between edittext and keyboard.
-
Bhavin Nattar almost 11 yearsWelcome buddy.. what i have done till now suggested you.. and try after adding
marginBottom Attribute
in EditText inxml
and if any of these suggestion worked for you then please tick this answer.. -
Bhavin Nattar almost 11 years@altosh: Buddy if my answer helped you then pls tick it so that other may know that it is correct answer...
-
Ian Lovejoy about 8 yearsPadding is what works, because unlike margins it is seen by the window manager as internal to the view. For example: editText.setPadding(0, 0, 0, 40) will cause your view to get an additional 40px of space beneath it when the keyboard appears. I did not have to set the gravity for this to work.
-
filthy_wizard about 8 yearswhat happens to the text inside the edittext if you do this?
-
filthy_wizard about 8 yearsno space between edittext and soft keyboard. cant figure it out
-
Ed Lee over 6 years@user1232726 if you set the height of the edit text to wrap_content, then your text would appear off-center but it would all be visible. Different story if, for example, you set the edit text height to 41dp and paddingBottom to 40dp
-
Jeffrey almost 6 years@filthy_wizard check the padding in your layout
-
The Fluffy T Rex about 4 yearsWhen I add padding it pushes the line under the EditText down as well, messing up the design. I, therefore, don't think this is the best solution
-
Alex Rivas almost 4 yearsi have a doubt this works for me but im using bottom navigation and this one ups to with the keyboard so the space is huge and you can see and press any navigation button