Skip to content Skip to sidebar Skip to footer

How To Prevent That The Keyboard Hides My Edittext?

I have a RelativeLayout at the top, then below i have a ListView in the center and finally at the bottom i have another relativeLayout with an EditText and a Button inside. I want

Solution 1:

You should not be setting your layout_width and layout_heights with explicit pixel values. Instead, use wrap_parent or fill_parent as appropriate.

If you want somethign like a text view to be a particular width, use dpi units which will adjust correctly on different screen resolutions.

Regarding your specific virtual keyboard problem, I would try setting up the ListView so it takes up the remaining space.

--Set the heights of everything except the ListView to wrap_parent --Set the ListView to fill_parent,

The ListView should take up however much space is available, and thus shrink when you ask it to resize.

Solution 2:

I had the same issue and I found a solution. In my case, in the Manifeste.xml, I declared a minSdkVersion=3 (Android 1.5), and my project was compiled with Android 2.2 (SDK 8).In theory, it should work... but not! I modified minsdkVersion to 4 (Android 1.6), then it's OK. It was just an compatibily issue between the different Android SDK. Good luck to you.

Solution 3:

if you by any chance are using this:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

this can cause the problem. I originally added that line to fix a bug where the status bar pushes the app downward... but it also prevents the keyboard from pushing the app upward.

sigh.

Solution 4:

U can add a scrollview like this :

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

..........


</ScrollView>

This would cause the app to focus on the edit text and adjust it to focus on screen ! it also works inside fragments!

Solution 5:

If EditText Field is been covered by the KeyBoard Use the following code:

EditText= findViewById(R.id.edittext)
EditText?.getParent()?.requestChildFocus(EditText,EditText)

If you want the Cursor to be in the Focused EditText than use EditText.requestFocus()after the EditText?.getParent()?.requestChildFocus(EditText,EditText) which helps to get the focus and Cursor in the Focused EditText.

Post a Comment for "How To Prevent That The Keyboard Hides My Edittext?"