Issue while setting WindowSoftInputMode to AdjustPan

孤者浪人 提交于 2020-01-05 02:39:18

问题


I’m working on Xamarin forms project. I’ve many Entry fields in my application, one of them is in popup and the popup opens in the centre of the device screen. Also few entry fields are in scroll view. The issue is only with the Android Application. For iOS it’s working perfectly. When I click on Entry field in side the popup, the soft key board is opened and the UI of my popup gets disturbed. So, I decided to set WindowSoftInputMode = SoftInput.AdjustPan to my main Activity. This solves my UI issue of the popups but now when I click on other entry fields,my ![scroll view stops scrolling] (few entry fields are in side scrollview).I tried by using AdjustResize and rest of other soft inputs, but of no use. Any ideas on how to get rid of this ?


回答1:


On Android Xamarin.Forms Application is working on a single Android Activity, so WindowSoftInputMode is set globally. You could do a dependency injection service. On iOS it would do nothing and on Android it would set WindowSoftInputMode to your desired value. Then use it to set WindowSoftInputMode before and after showing your Popup.

In Xamarin.Forms Forms.Context is the Activity.

var window = ((Activity)Forms.Context).Window;
window.SetSoftInputMode(SoftInput.AdjustPan);



回答2:


In case of

Xamarin Android

you can access window directly from mainActivity Like so:

Window.SetSoftInputMode(Android.Views.SoftInput.AdjustPan);

or in AndroidManifest.xml

<activity android:name=".myActivity"
 android:label="@string/app_name"
 android:screenOrientation="sensorPortrait"
 android:windowSoftInputMode="adjustPan"/>


来源:https://stackoverflow.com/questions/31450760/issue-while-setting-windowsoftinputmode-to-adjustpan

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!