Scroll editor in Xamarin Forms into view

前端 未结 6 1098
天涯浪人
天涯浪人 2021-02-02 01:49

Using Xamarin Forms, consider the Xaml below.


   

        
6条回答
  •  梦毁少年i
    2021-02-02 02:20

    Using ScrollView as mentioned above fixes problem in iOS and partially fixes in Android. To fully fix problem in android, I found another simple and nice addition.

    Only in android I replace Xamarin forms Editor with android specific TextEdit control. So in my Page constructor I have following code just for android.

    #if __ANDROID__
             // I have editor defined in xaml named ReportTextEditor in stacklayout named MainStackLayout
            Editor sharedEditor = this.ReportTextEditor;
            MainStackLayout.Children.Remove(sharedEditor); //removing the ReportTextEditor which was defined in xaml
            EditText editText = new EditText(Forms.Context); //created android specific editor
            editText.InputType = InputTypes.ClassText | InputTypes.TextFlagAutoCorrect | InputTypes.TextFlagCapSentences | InputTypes.TextFlagMultiLine; //keyboard options, optional
            MainStackLayout.Children.Add(editText); //Added android specific edit text to my stack layout
    
    #endif
    

    You also need to add android specific namespaces as needed.

    #if __ANDROID__
    using Xamarin.Forms.Platform.Android;
    using Android.Widget;
    using Button = Xamarin.Forms.Button;
    using Android.Text;
    #endif
    

提交回复
热议问题