How to prevent Editor to go behind the keyboard in Xamarin.Forms?

后端 未结 3 1920
悲哀的现实
悲哀的现实 2021-01-22 18:39

I have a Chat app. Currently, there is an Entry control for add chat text. Now I want to provide multiline Entry, same like Whatsapp.

  • If user type more than one li
3条回答
  •  暖寄归人
    2021-01-22 19:18

    For Ios there is one plugin. You can use that. The link is Here.

    For Andorid you have to just set below code in MainActivity after LoadApplication(new App()) method.

    App.Current.On

    Updated answer for iOS :

    For IOS you can use the following custom renderer to solve the keyboard overlapping issue. And please removed the keyboardoverlap nuget package from the project.

    using System;
    using UIKit;
    using Xamarin.Forms;
    using Xamarin.Forms.Platform.iOS;
    using HBIClientFacingApp;
    using HBIClientFacingApp.iOS;
    
    [assembly:ExportRenderer( typeof(CustomEditor), typeof(CustomEditorRenderer))]
    namespace YourNameSpace.iOS
    {
        public class CustomEditorRenderer: EditorRenderer
        {
            public ChatEntryRenderer()
            {   
                UIKeyboard.Notifications.ObserveWillShow ((sender, args) => {
    
                    if (Element != null)
                    {
                        Element.Margin = new Thickness(0,0,0, args.FrameEnd.Height); //push the entry up to keyboard height when keyboard is activated
                    }
                });
    
                UIKeyboard.Notifications.ObserveWillHide ((sender, args) => {
    
                    if (Element != null)
                    {
                           Element.Margin = new Thickness(0); //set the margins to zero when keyboard is dismissed
                    }
    
                }); 
            }
        }
    }
    

提交回复
热议问题