如何移动布局时,软键盘显示 Android

我有一个登录屏幕与两个 EditTexts和登录按钮在我的布局。问题是,当我开始输入时,软键盘会显示出来并覆盖登录按钮。当键盘出现时,如何将布局向上或向上推?

我不想使用一个 ScrollView,只是想实现它没有向下滚动。请给我一些建议。先谢谢你。

134032 次浏览

Try this in the android manifest file corresponding to the activity.

<activity android:windowSoftInputMode="adjustPan"> </activity>

Set windowSoftInputMode property to adjustPan and adjustResize

<activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>

Make use of Relative layout it will adjust the view so that you can see that view while typing the text

I somehow achieved this by knowing the status of the soft keyboard on the device. i move the layout to y position when the keyboard is shown and moved back to its original position when not shown. this works fine, followed this guidelines.

Use this code in onCreate() method:

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

Accoding to this guide, the correct way to achieve this is by declaring in your manifest:

<activity name="EditContactActivity"
android:windowSoftInputMode="stateVisible|adjustResize">


</activity>

This works like a charm for me

getDialog().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);

Put this line in activity declaration time in manifest.xml

<android:windowSoftInputMode="adjustPan">

This is all that is needed:

<activity android:windowSoftInputMode="adjustResize"> </activity>

Put this in your activity declaration in manifest file <activity android:windowSoftInputMode="adjustPan|adjustResize"> </activity>

or if you want you can add in onCreate() method of your activity

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);

only

android:windowSoftInputMode="adjustResize"

in your activity tag inside Manifest file will do the trick

When the softkeyboard appears, it changes the size of main layout, and what you need do is to make a listener for that mainlayout and within that listener, add the code scrollT0(x,y) to scroll up.

You should use

android:windowSoftInputMode="adjustPan|stateHidden"

in your AndroidManifest.xml file where you are declaring your activity. This will adjust your layout contents, when keyboard is shown in the layout.

If you are working with xamarin, you can put this code WindowSoftInputMode =Android.Views.SoftInput.AdjustPan | Android.Views.SoftInput.AdjustResize in activity attribute of the MainActivity class. For example, now the activity attribute will look like below

    [Activity(WindowSoftInputMode =Android.Views.SoftInput.AdjustPan | Android.Views.SoftInput.AdjustResize)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsApplicationActivity
{
//some code here.
}
android:fitsSystemWindows="true"

add property on main layout of layout file and

android:windowSoftInputMode="adjustResize"

add line in your Manifest.xml file on your Activty

its perfect work for me.

This will definitely work for you.

android:windowSoftInputMode="adjustPan"

I solve this by adding code into manifest:

<activity android:name=".Login"
android:fitsSystemWindows="true"
android:windowSoftInputMode="stateHidden|adjustPan"
</activity>