[Android] Keyboard Scroll

jb_tcjb_tc USMember ✭✭
edited September 5 in Xamarin.Forms

Hello,

I have a login form in my app. If the Entry is entered, the keyboard open.

But the problem is, that I can't scroll. So I have to close the keyboard to enter the other entry. This is not good!

So, I looked and found some tips. For example, I added that code before the base.OnCreate(..);

Window.SetSoftInputMode(SoftInput.AdjustResize);

But it is still not working.
On iOS it works finde!

Has anybody a solution for me?

My Xaml:

<?xml version="1.0" encoding="UTF-8"?>
<tccore:ExtendedContentPage 
    xmlns="http://xamarin.com/schemas/2014/forms" 
    xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
    xmlns:tccore="clr-namespace:TC.App.Page"
    xmlns:tccontrols="clr-namespace:TC.App.Controls;assembly=TC"
    x:Class="cc.Pages.Login"
    BackgroundColor="White">
    <ScrollView>
        <StackLayout WidthRequest="450" Orientation="Vertical" HorizontalOptions="Center" VerticalOptions="Center">
            <StackLayout VerticalOptions="CenterAndExpand" Padding="15,0,15,0">

                <Image Source="az" HorizontalOptions="Center" HeightRequest="180" WidthRequest="180" Margin="0,0,0,30"/>

                <tccontrols:ExtendedEntry 
                    Text="{Binding Path=Username}" 
                    x:Name="usernameEntry" 
                    HeightRequest="50" 
                    BackgroundColor="#eee" 
                    Placeholder="Kundennummer" 
                    PlaceholderColor="#363636"
                    TextColor="#363636"
                    Border="No"
                    FontFamily="SourceSansPro-Regular"
                    FontSize="13"
                    Margin="0,0,0,10"
                    Keyboard="Text">

                    <tccontrols:ExtendedEntry.Padding>
                        <OnPlatform 
                            x:TypeArguments="x:String" 
                            iOS="20,5,20,5" 
                            Android="40,0,40,0" />
                    </tccontrols:ExtendedEntry.Padding>

                </tccontrols:ExtendedEntry>

                <tccontrols:ExtendedEntry 
                    Text="{Binding Path=Username}"
                    IsPassword="true"
                    x:Name="passwordEntry" 
                    HeightRequest="50" 
                    BackgroundColor="#eee" 
                    Placeholder="Passwort" 
                    PlaceholderColor="#363636"
                    TextColor="#363636"
                    Border="No"
                    FontFamily="SourceSansPro-Regular"
                    Padding="20,5,20,5"
                    FontSize="13"
                    Margin="0,0,0,0">
                     <tccontrols:ExtendedEntry.Padding>
                        <OnPlatform 
                            x:TypeArguments="x:String" 
                            iOS="20,5,20,5" 
                            Android="40,0,40,0" />
                    </tccontrols:ExtendedEntry.Padding>
                 </tccontrols:ExtendedEntry>

                <StackLayout Margin="0,20,0,20" Orientation="Horizontal" Spacing="0"> 
                    <Switch IsToggled="true" HorizontalOptions="Start" VerticalOptions="Center" x:Name="SwitchSaveLogin" Margin="0,0,15,0"/>
                    <Label Text="Logindaten speichern" FontSize="13" FontFamily="SourceSansPro-Regular" VerticalOptions="Center" HorizontalOptions="Start" />
                </StackLayout>

                <Button BackgroundColor="#004b97" FontFamily="SourceSansPro-Regular" Text="Einloggen" TextColor="#fff" HorizontalOptions="Fill" HeightRequest="50" Clicked="Handle_LoginClicked" BorderRadius="0" />

                <StackLayout Margin="0,20,0,0" Orientation="Horizontal" HorizontalOptions="Center" Spacing="0"> 
                    <Label
                        HorizontalOptions="Center"
                        FontSize="13"
                        FontFamily="SourceSansPro-Regular"
                        Text="Möchten Sie die App als "/>

                     <Label
                        x:Name="goAsGuest"
                        HorizontalOptions="Center"
                        FontSize="13"
                        Text="Gast verwenden"
                        FontFamily="SourceSansPro-Bold"
                        TextColor="#004f9f"/>
                   <Label
                        HorizontalOptions="Center"
                        FontSize="13"
                        FontFamily="SourceSansPro-Regular"
                        Text=","/>

                </StackLayout>

                <StackLayout Orientation="Horizontal" Spacing="0" HorizontalOptions="Center" > 
                    <Label
                        HorizontalOptions="Start"
                        Text=" einen "
                        FontFamily="SourceSansPro-Regular"
                        FontSize="13"/>

                      <Label
                        x:Name="becomeCustomer"
                        HorizontalTextAlignment="Center"
                        HorizontalOptions="Center"
                        FontSize="13"
                        Text="Shop Zugang anfordern"
                        FontFamily="SourceSansPro-Bold"
                        TextColor="#004f9f"/>

                     <Label
                        HorizontalOptions="Start"
                        Text=" oder haben"
                        FontFamily="SourceSansPro-Regular"
                        FontSize="13"/>
                </StackLayout>

                <StackLayout Orientation="Horizontal" Spacing="0" HorizontalOptions="Center" > 
                      <Label
                        HorizontalOptions="Start"
                        Text="Sie Ihr "
                        FontFamily="SourceSansPro-Regular"
                        FontSize="13"/>

                     <Label
                        Text="Passwort vergessen"
                        x:Name="forgotPassword"
                        FontFamily="SourceSansPro-Bold"
                        FontSize="13"
                        TextColor="#004f9f"/>
                    <Label
                        Text="?"
                        FontFamily="SourceSansPro-Regular"
                        FontSize="13"/>
                </StackLayout>
            </StackLayout>
        </StackLayout>
    </ScrollView>
</tccore:ExtendedContentPage>

Best Answers

  • jb_tcjb_tc USMember ✭✭
    edited September 5 Accepted Answer

    @JohnHardman

    after adding this:

    Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
    

    the scrolling worked fine. But now the Statusbar has another color and under the statusbar is an empty blue bar:

    Any idea?

    Update

    Fixed by call this method in MainActivity -> OnCreate

    ```private void InitializeUI()
    {
    // from https://forums.xamarin.com/discussion/comment/282515#Comment_282515

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Window.DecorView.SystemUiVisibility = 0;
    
                var statusBarHeightInfo = typeof(Xamarin.Forms.Platform.Android.FormsAppCompatActivity).GetField("_statusBarHeight",
                    System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    
                if (statusBarHeightInfo != null)
                {
                    statusBarHeightInfo.SetValue(this, 0);
                }
    
                Window.SetStatusBarColor(
                    new Android.Graphics.Color(0, 75, 151)
                ); 
            } 
        }```
    
  • jb_tcjb_tc USMember ✭✭
    edited September 5 Accepted Answer

    Hi,

    I still get the problem that the statusbar color is white..

    I can't change them to blue or something like that:

    Window.SetStatusBarColor(
                    new Android.Graphics.Color(0, 75, 151)
                ); 
    

    Update

    Fixed!
    I have to call the function "SetStatusBarColor" after base.OnCreate(..);

Answers

  • RasmusVindRasmusVind USMember ✭✭

    +1 i am looking for a solution to this too.

  • jb_tcjb_tc USMember ✭✭
    edited September 5 Accepted Answer

    @JohnHardman

    after adding this:

    Xamarin.Forms.Application.Current.On<Xamarin.Forms.PlatformConfiguration.Android>().UseWindowSoftInputModeAdjust(WindowSoftInputModeAdjust.Resize);
    

    the scrolling worked fine. But now the Statusbar has another color and under the statusbar is an empty blue bar:

    Any idea?

    Update

    Fixed by call this method in MainActivity -> OnCreate

    ```private void InitializeUI()
    {
    // from https://forums.xamarin.com/discussion/comment/282515#Comment_282515

            if (Build.VERSION.SdkInt >= BuildVersionCodes.Lollipop)
            {
                Window.DecorView.SystemUiVisibility = 0;
    
                var statusBarHeightInfo = typeof(Xamarin.Forms.Platform.Android.FormsAppCompatActivity).GetField("_statusBarHeight",
                    System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic);
    
                if (statusBarHeightInfo != null)
                {
                    statusBarHeightInfo.SetValue(this, 0);
                }
    
                Window.SetStatusBarColor(
                    new Android.Graphics.Color(0, 75, 151)
                ); 
            } 
        }```
    
  • jb_tcjb_tc USMember ✭✭
    edited September 5 Accepted Answer

    Hi,

    I still get the problem that the statusbar color is white..

    I can't change them to blue or something like that:

    Window.SetStatusBarColor(
                    new Android.Graphics.Color(0, 75, 151)
                ); 
    

    Update

    Fixed!
    I have to call the function "SetStatusBarColor" after base.OnCreate(..);

  • JohnHardmanJohnHardman GBUniversity ✭✭✭✭✭

    @hh-devs - What does your styles.xml contain (in the Android project)? That's where you would normally set colors relating to Android-specific bits.

  • jb_tcjb_tc USMember ✭✭

    @JohnHardman see my updated answer above. :)

    Thank you!!

Sign In or Register to comment.